difference<T> function Set operations

Set<T> difference<T>(
  1. Iterable<T> iterable,
  2. Iterable<Iterable<Object?>> others
)

Returns a new set containing every value in iterable that is not in any of the others iterables.

difference([0, 1, 2, 0], [[1]]); // {0, 2}

Implementation

Set<T> difference<T>(Iterable<T> iterable, Iterable<Iterable<Object?>> others) {
  var set = Set.of(iterable);
  for (final other in others) {
    for (final o in other) {
      set.remove(o);
    }
  }
  return set;
}