cmpBy<U> method

  1. @override
int cmpBy<U>(
  1. Iterator<U> other,
  2. int f(
    1. T,
    2. U
    )
)

Lexicographically compares the elements of this Iterator with those of another with respect to the specified comparison function. Less = -1 Equal = 0 Greater = 1

Implementation

@override
int cmpBy<U>(Iterator<U> other, int Function(T, U) f) {
  while (true) {
    if (moveNext()) {
      if (other.moveNext()) {
        final cmp = f(current, other.current);
        if (cmp != 0) {
          return cmp;
        }
      } else {
        return 1;
      }
    } else {
      if (other.moveNext()) {
        return -1;
      }
      return 0;
    }
  }
}