max property

  1. @useResult
E? get max

The maximum element in this iterable, or null if empty.

['a', 'c', 'b'].max; // 'c'

Implementation

@useResult E? get max {
  final iterator = this.iterator;
  if (!iterator.moveNext()) {
    return null;
  }

  var max = iterator.current;
  while (iterator.moveNext()) {
    final element = iterator.current;
    if (max.compareTo(element) < 0) {
      max = element;
    }
  }

  return max;
}