A screw can belong to several categories at once: rounded head, torx drive, wood material. A photo can likewise belong to albums for a person, place, and event. Set operations combine those overlapping groups without forcing them into a single hierarchy. They answer questions about membership: which items belong to either group, both groups, or one group but not another? section 13.1 section 13.5
In Julia, three operations cover the basic choices:
- `union(A, B)` or `A ∪ B` includes elements in A or B. section 13.3
- `intersect(A, B)` or `A ∩ B` includes only elements shared by both. `intersect` can also take several sets. section 13.3 section 13.5
- `setdiff(A, B)` keeps elements in A that are absent from B. Order matters: `setdiff(B, A)` asks a different question. section 13.3
Find matching products
Store each screw’s product number in the sets for its attributes. Then `intersect(rounded, torx, wood)` returns product numbers 124 and 128: screws satisfying all three conditions. To find T-slot screws that are not plastic, use `setdiff(tslot, plastic)`. The same membership logic works for photo captions: `(bob ∪ eve) ∩ joe` selects captions shared with Joe and at least one of Bob or Eve. section 13.5 section 13.3
Sets are designed for these operations; Julia arrays can also participate, but are efficient for set operations only when the collections are small. For richer records, filter `Screw` objects into reusable sets, or keep product numbers in sets and look up the matching objects in a dictionary keyed by product number. The same pattern can search a bug tracker by intersecting sets of bug numbers grouped by assignee, severity, and project. section 13.3 section 13.5.5 section 13.5.4 section 13.6
The Venn diagrams show which elements remain after union, intersection, and difference. section 13.3

