difference<T> static method

CustomSet<T> difference<T>(
  1. CustomSet<T> a,
  2. CustomSet<T> b
)

Returns the difference of two sets.

Notation: A - B = {x | x ∈ A and x ∉ B}

The difference contains all elements that are in the first set but not in the second set.

Example:

final a = CustomSet<int>([1, 2, 3, 4, 5]);
final b = CustomSet<int>([2, 4]);
final result = SetOperations.difference(a, b);
// result = {1, 3, 5}

Implementation

static CustomSet<T> difference<T>(CustomSet<T> a, CustomSet<T> b) =>
    CustomSet(a.elements.where((e) => !b.contains(e)));