maxOfWithOrNull<R> method
Returns the largest value according to the provided comparator
among all
values produced by selector
function applied to each element in the
collection or null
if there are no elements.
Implementation
R? maxOfWithOrNull<R>(
Comparator<R> comparator,
R Function(E element) selector,
) {
if (isEmpty) return null;
final iterator = this.iterator..moveNext();
var maxValue = selector(iterator.current);
while (iterator.moveNext()) {
final value = selector(iterator.current);
if (comparator(maxValue, value) < 0) maxValue = value;
}
return maxValue;
}