Fusonic\Linq\Linq::max PHP Method

max() public method

Returns the maximum item value according to $func
public max ( callable $func = null ) : double
$func callable A func that returns any numeric type (int, float etc.)
return double Maximum item value
    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;
    }