maxByKey<U extends Comparable<U>> method

  1. @override
Option<T> maxByKey<U extends Comparable<U>>(
  1. U f(
    1. T
    )
)

Returns the element that gives the maximum value from the specified function.

Implementation

@override
Option<T> maxByKey<U extends Comparable<U>>(U Function(T) f) {
  T max;
  U maxVal;
  if (moveNext()) {
    max = current;
    maxVal = f(max);
  } else {
    return None;
  }
  for (final element in this) {
    final val = f(element);
    if (val.compareTo(maxVal) > 0) {
      max = element;
      maxVal = val;
    }
  }
  return Some(max);
}