isSorted method

bool isSorted()

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

Implementation

bool isSorted() {
  while (moveNext()) {
    var prevVal = current;
    if (moveNext()) {
      if (prevVal.compareTo(current) > 0) {
        return false;
      }
    }
  }
  return true;
}