minBy method

E? minBy(
  1. Comparable sortKey(
    1. E
    )
)

Returns the element of this with the least value for sortKey, or null if this is empty.

This method is guaranteed to calculate sortKey only once for each element.

Example:

['a', 'aaa', 'aa'].minBy((e) => e.length).value; // 'a'

Implementation

E? minBy(Comparable<dynamic> Function(E) sortKey) {
  final sortKeyCache = <E, Comparable<dynamic>>{};
  return this.min((a, b) => sortKeyCompare<E>(a, b, sortKey, sortKeyCache));
}