max< T> function
Returns the maximum value in i
, according to the order specified by the
compare
function, or null
if i
is empty.
The compare function must act as a Comparator. If compare
is omitted,
Comparable.compare is used. If i
contains null elements, an exception
will be thrown.
Implementation
T max<T>(Iterable<T> i, [Comparator<T> compare]) {
if (i.isEmpty) return null;
final Comparator<T> _compare = compare ?? Comparable.compare;
return i.isEmpty ? null : i.reduce((a, b) => _compare(a, b) > 0 ? a : b);
}