max property

  1. @useResult
E? get max

The element with the maximum value returned by this Order's function, or null if empty.

final list = [('a', 2), ('c', 3), ('b', 1)];
list.order(by: (foo) => foo.$2).min; // ('c', 3)

Implementation

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

  var max = iterator.current;
  var maxValue = _function(max);

  while (iterator.moveNext()) {
    final value = _function(iterator.current);
    if (maxValue.compareTo(value) < 0) {
      max = iterator.current;
      maxValue = value;
    }
  }

  return max;
}