Create ordered pairs with setCartesian
setCartesian returns the Cartesian product of sets: every ordered pairing of one item from each input set. It is useful for grids, state spaces, and combining independent choices.
Example
The product of {a,b} and {1,2} contains (a,1), (a,2), (b,1), and (b,2). Use setSize to check cardinality; for finite sets, sizes multiply. combinations instead selects items from one collection.
Caveats
Order in each resulting tuple matters, and products grow quickly. Deduplicate inputs first with setDistinct if repeated values are not meaningful. Use setUnion when you need merged members, not paired members.