minE method
Returns the minimum value in the enumerable.
Iterates over the enumerable and applies the sorter
property of the
given EqualityComparer to each element in order to find the maximum
value. Once iteration is complete, minE will return the largest element
found.
When the type of the enumerable is one of the below types, the EqualityComparer can be omitted. In this case, the function defaults to predefined minimum functions depending on the type:
- Numeric types (
num
,int
,double
) return the minimum of all elements as defined by themin
function indart:math
. String
types return the alphabetic minimum of all elements.
If the enumerable type is not one of these types, the EqualityComparer
must be provided. Otherwise, an ArgumentError
will be thrown.
If the enumerable is empty, an EmptyEnumerableError
will be thrown.
The minE function will iterate over every element in the enumerable.
Implementation
T minE([EqualityComparer<T> comparer]) {
IncompatibleTypeError.checkValidTypeOrParam(
T, MinReducers.director.keys, comparer);
if (comparer == null) {
return MinReducers.director[T](this);
}
final iterator = this.iterator;
if (!iterator.moveNext()) throw EnumerableError.isEmpty();
T min;
do {
if (min == null)
min = iterator.current;
else if (comparer.sort(min, iterator.current) > 0) {
min = iterator.current;
}
} while (iterator.moveNext());
return min;
}