minOf<R extends Comparable> method

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

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

Throws a NoSuchElementException if the list is empty.

Implementation

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