dedupBy method

void dedupBy(
  1. bool f(
    1. T a,
    2. T b
    )
)

Removes all but the first of consecutive elements in the vector satisfying a given equality relation. If the vector is sorted, this removes all duplicates.

Implementation

void dedupBy(bool Function(T a, T b) f) {
  late T last;
  bool first = true;
  removeWhere((element) {
    if (first) {
      last = element;
      first = false;
      return false;
    }
    if (f(element, last)) {
      return true;
    }
    last = element;
    return false;
  });
}