isSortedBy method

  1. @override
bool isSortedBy(
  1. int f(
    1. T,
    2. T
    )
)

Checks if the elements of this iterator are sorted by f. That is, for each element f(a,b) and its following element f(b,c), f(a,b) <= f(b,c) 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 isSortedBy(int Function(T, T) f) {
  T prev;
  if (moveNext()) {
    prev = current;
  } else {
    return true;
  }
  for (final element in this) {
    if (f(prev, element) > 0) {
      return false;
    }
    prev = element;
  }
  return true;
}