intersection<T> static method

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

Returns the intersection of two sets.

Notation: A ∩ B = {x | x ∈ A and x ∈ B}

The intersection contains all elements that are present in both sets.

Example:

final a = CustomSet<int>([2, 4, 6, 8, 10]);
final b = CustomSet<int>([4, 10, 14, 18]);
final result = SetOperations.intersection(a, b);
// result = {4, 10}

Implementation

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