isSortedByKey<U extends Comparable<U>> method

  1. @override
bool isSortedByKey<U extends Comparable<U>>(
  1. U f(
    1. T
    )
)

Checks if the elements of this iterator are sorted by a key. That is, for each element f(a) and its following element f(b), f(a) <= f(b) must hold. If the iterator yields exactly zero or one element, true is returned. negative if a < b zero if a == b positive if a > b

Implementation

@override
bool isSortedByKey<U extends Comparable<U>>(U Function(T) f) {
  U prev;
  if (moveNext()) {
    prev = f(current);
  } else {
    return true;
  }
  for (final element in this) {
    final val = f(element);
    if (prev.compareTo(val) > 0) {
      return false;
    }
    prev = val;
  }
  return true;
}