public function max(callable $func = null)
{
$max = null;
$iterator = $this->getSelectIteratorOrInnerIterator($func);
foreach ($iterator as $value) {
if (!is_numeric($value) && !is_string($value) && !$value instanceof \DateTime) {
throw new UnexpectedValueException("max() only works on numeric values, strings and DateTime objects.");
}
if (is_null($max)) {
$max = $value;
} elseif ($max < $value) {
$max = $value;
}
}
if ($max === null) {
throw new \RuntimeException("Cannot calculate max() as the Linq sequence contains no elements.");
}
return $max;
}