librarylibs/Sets/src/Sets.xtl
Sets: vectors as sets -- union, intersection, difference, subset, and how often each item occurs. Import it with an alias of your choice: "se:" u_se< "Sets". Put libs/Sets/src on XETAL_PATH ("just path"); the reference is libs/Sets/docs. Names with l: are exported; those under h: are private to this file.
A set is a vector of any type with equality (numbers, characters, boxes); results have no repeats and keep the order in which items are first seen, left argument first.
Combining
ˡu̲nion : Eq a => a -> a -> a
a u_nion b: the items of either.
ˡu̲nion ← { a b → u̲nique a c̲at b }
ˡi̲ntersect : Eq a => a -> a -> a
a i_ntersect b: the items of a that are also in b.
ˡi̲ntersect ← { a b → u ← u̲nique a◆ (u m̲ember? b) r̲eplicate u }
ˡd̲ifference : Eq a => a -> a -> a
a d_ifference b: the items of a that are not in b.
ˡd̲ifference ← { a b → u ← u̲nique a◆ (n̲ot u m̲ember? b) r̲eplicate u }
ˡs̲ymmetric : Eq a => a -> a -> a
a s_ymmetric b: the items in one but not both.
ˡs̲ymmetric ← { a b → (a ˡd̲ifference b) c̲at b ˡd̲ifference a }
Comparing
ˡs̲ubset? : (Eq a, Truthy b) => a -> a -> b
a s_ubset? b: whether every item of a is in b.
ˡs̲ubset? ← { a b → '∧ r̲/ a m̲ember? b }
ˡs̲ame? : (Eq a, Truthy b) => a -> a -> b
a s_ame? b: whether a and b hold the same items, ignoring order and repeats.
ˡs̲ame? ← { a b → (a ˡs̲ubset? b) ∧ b ˡs̲ubset? a }
ˡd̲isjoint? : (Eq a, Truthy b) => a -> a -> b
a d_isjoint? b: whether no item is in both.
ˡd̲isjoint? ← { a b → n̲ot '∨ r̲/ a m̲ember? b }