minBy<K extends Comparable<K>> method

T? minBy<K extends Comparable<K>>(
  1. K selector(
    1. T element
    )
)

Finds the minimum value based on a selector or returns null if empty or all null.

Example:

Iterable<int?>? numbers = [3, 5, 2, null];
print(numbers.minBy((num) => num!)); // Output: 2

Implementation

T? minBy<K extends Comparable<K>>(K Function(T element) selector) =>
    validate().reduceOrNull(
        (a, b) => selector(a).compareTo(selector(b)) <= 0 ? a : b);