isSortedByCompare<K> method

*<Null safety>*

bool isSortedByCompare <K>(K keyOf(T element), Comparator<K> compare)

Implementation

bool isSortedByCompare<K>(
    K Function(T element) keyOf, Comparator<K> compare) {
  var iterator = this.iterator;
  if (!iterator.moveNext()) return true;
  var previousKey = keyOf(iterator.current);
  while (iterator.moveNext()) {
    var key = keyOf(iterator.current);
    if (compare(previousKey, key) > 0) return false;
    previousKey = key;
  }
  return true;
}