maxBy method

T? maxBy(
  1. int f(
    1. T,
    2. T
    )
)

Returns the element that gives the maximum value with respect to the specified comparison function.

Implementation

T? maxBy(int Function(T, T) f) {
  T max;
  if (moveNext()) {
    max = current;
  } else {
    return null;
  }
  for (final element in this) {
    if (f(element, max) > 0) {
      max = element;
    }
  }
  return max;
}