maxOf<R extends Comparable> method

R maxOf<R extends Comparable>(
  1. R selector(
    1. T
    )
)

Returns the largest value among all values produced by selector function applied to each element in the collection.

Throws a NoSuchElementException if the list is empty.

Implementation

R maxOf<R extends Comparable>(R Function(T) selector) {
  final i = iterator();
  if (!i.hasNext()) {
    throw const NoSuchElementException("Collection is empty.");
  }
  R maxValue = selector(i.next());
  while (i.hasNext()) {
    final v = selector(i.next());
    if (maxValue.compareTo(v) < 0) {
      maxValue = v;
    }
  }
  return maxValue;
}