and method

  1. @useResult
Comparator<T> and(
  1. Comparator<T> tiebreaker
)

Returns a Comparator that uses tiebreaker to break ties.

final Comparator<(int, int)> foo = (a, b) => a.$1.compareTo(b.$1);
foo((1, 1), (1, 2)); // 0

final bar = foo.and((a, b) => a.$2.compareTo(b.$2));
bar((1, 1), (1, 2)); // -1

Implementation

@useResult Comparator<T> and(Comparator<T> tiebreaker) => (a, b) => switch(this(a, b)) {
  0 => tiebreaker(a, b),
  final value => value,
};