minimumBy method
Returns the minimal value based on the comparator
function.
Example:
[1, 0, 2].minBy((a, b) => a.compareTo(b)); // 0
persons.minBy((a, b) => a.age.compareTo(b.age)); // the youngest person
Implementation
T? minimumBy(Comparator<T> comparator) {
ArgumentError.checkNotNull(comparator, 'comparator');
if (isEmpty) return null;
return reduce(
(value, element) => comparator(value, element) < 0 ? value : element);
}