Fusonic\Linq\Linq::min PHP Method

min() public method

Gets the minimum item value of all items or by invoking a transform function on each item to get a numeric value.
public min ( callable $func = null ) : double
$func callable A func that returns any numeric type (int, float etc.) from the given element, or NULL to use the element itself.
return double Minimum item value
    public function min(callable $func = null)
    {
        $min = null;
        $iterator = $this->getSelectIteratorOrInnerIterator($func);
        foreach ($iterator as $value) {
            if (!is_numeric($value) && !is_string($value) && !$value instanceof \DateTime) {
                throw new UnexpectedValueException("min() only works on numeric values, strings and DateTime objects.");
            }
            if (is_null($min)) {
                $min = $value;
            } elseif ($min > $value) {
                $min = $value;
            }
        }
        if ($min === null) {
            throw new \RuntimeException("Cannot calculate min() as the Linq sequence contains no elements.");
        }
        return $min;
    }