minByKey<U extends Comparable<U>> method

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

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

Implementation

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