maxOrNull method

T? maxOrNull()

Returns the largest element or null if there are no elements.

Implementation

T? maxOrNull() {
  final i = iterator();
  if (!iterator().hasNext()) return null;
  T max = i.next();
  while (i.hasNext()) {
    final T e = i.next();
    if (Comparable.compare(max, e) < 0) {
      max = e;
    }
  }
  return max;
}