Operators
Set operators
FullMembership, union, intersection and subset over lists treated as sets.
Raku has set-theoretic infixes that treat their operands as sets. Each has a Unicode spelling (∈, ∪, ∩, ⊆) and an ASCII equivalent written in parentheses — (elem), (|), (&), (<=).
Membership — (elem) #
say 2 (elem) (1, 2, 3); say 9 (elem) (1, 2, 3);
Output
True
FalseUnion and intersection #
(|) is union, (&) is intersection; both return a Set.
say (1, 2, 3) (|) (3, 4); say (1, 2, 3) (&) (2, 3, 4);
Output
Set(1 2 3 4)
Set(2 3)Subset — (<=) #
(<=) tests whether the left set is contained in the right.
say (1, 2) (<=) (1, 2, 3);
Output
TrueNotes #
- Each ASCII operator mirrors a Unicode one:
(elem)=∈,(|)=∪,(&)=∩,(<=)=⊆, plus(-)=∖for set difference. - A
Setdeduplicates and is unordered; comparing sets ((==)) ignores order and repetition, unlike listeqv. - Operands are coerced to sets, so
(1, 1, 2) (|) (2)isSet(1 2)— duplicates collapse.