maxBy method

  1. @override
Option<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

@override
Option<T> maxBy(int Function(T, T) f) {
  T max;
  if (moveNext()) {
    max = current;
  } else {
    return None;
  }
  for (final element in this) {
    if (f(element, max) > 0) {
      max = element;
    }
  }
  return Some(max);
}