max method

E? max([
  1. Comparator<E>? compare
])

Returns the maximum value in iterable, according to the order specified by the compare function, or null if iterable is empty.

The compare function must act as a Comparator. If compare is omitted, Comparable.compare is used. If iterable contains null elements, an exception will be thrown.

Implementation

E? max([Comparator<E>? compare]) {
  if (isEmpty) return null;
  final compare0 = compare ?? _compareAny;
  return reduce((a, b) => compare0(a, b) > 0 ? a : b);
}