intersection method

CustomSet<T> intersection(
  1. CustomSet<T> other
)

Returns the intersection of this set with other.

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 = a.intersection(b);
// result = {4, 10}

Implementation

CustomSet<T> intersection(CustomSet<T> other) =>
    CustomSet(_elements.where(other._elements.contains));