Set union combines collections and returns each distinct element found in at least one input. In Julia, write union(A, B) or use the ∪ operator. For example, union([1, 2, 4], [1, 3]) contains 1, 2, 3, and 4. section 13.3
Union answers an “A or B” question: include elements from the first collection or the second. Sets are designed for these operations and remove duplicates; arrays can also participate, but are less efficient for large collections. section 13.3 section 13.8
Use union when you need to:
- Combine two groups of records without repeating shared elements. section 13.3
- Prepare a larger group before applying another set operation such as intersection. section 13.3
- Choose between readable operator notation, A ∪ B, and the explicit function call, union(A, B). section 13.3
Finding photos from either destination
If Spain and Greece contain photos from two trips, Spain ∪ Greece produces the distinct photos from either destination. To keep only Bob’s photos, combine the operations as Bob ∩ (Spain ∪ Greece), or intersect(Bob, union(Spain, Greece)). section 13.3
S = Bob ∩ (Spain ∪ Greece) S = intersect(Bob, union(Spain, Greece))
A compact example shows union nested inside intersection, making the “either destination, then Bob” filtering pattern directly runnable. section 13.3



