maxByOrNull<R extends Comparable<R> > method
E?
maxByOrNull<R extends Comparable<R> >(
- R selector(
- E element
Implementation
E? maxByOrNull<R extends Comparable<R>>(R Function(E element) selector) {
if (isEmpty) return null;
var maxElement = first;
var maxValue = selector(maxElement!);
for (final element in this) {
final value = selector(element);
if (value.compareTo(maxValue) > 0) {
maxElement = element;
maxValue = value;
}
}
return maxElement;
}