maxBy<R extends Comparable> method
T?
maxBy<R extends Comparable>(
- R selector(
- T
Returns the first element yielding the largest value of the given function or null
if there are no elements.
Implementation
T? maxBy<R extends Comparable>(R Function(T) selector) {
final i = iterator();
if (!iterator().hasNext()) return null;
T maxElement = i.next();
R maxValue = selector(maxElement);
while (i.hasNext()) {
final e = i.next();
final v = selector(e);
if (maxValue.compareTo(v) < 0) {
maxElement = e;
maxValue = v;
}
}
return maxElement;
}