In Julia, you write a superset by constructing a collection that contains every element of each original set, then reducing it to unique elements — most idiomatically with union(set1, set2, ...) from Base, or by folding with union over a vector of sets; a "superset" in this sense is just the set-theoretic union, and Julia's Set type removes duplicates automatically. The word "superset" can hide two different questions, though: do you want a new set equal to the union, or do you want to test whether one set is a superset of another? Julia supports both, and the choice determines the function you reach for. Below, "superset" means the union of given sets unless the testing sense is named explicitly.

The direct answer: union gives you the union of sets

Julia's Base.union accepts multiple iterables and returns a collection with the distinct elements of all of them. With Set arguments, you get a Set back, and duplicate membership collapses:

The same call works with vectors, ranges, tuples, and strings-as-iterables, but the return type follows Julia's promotion rules for collections rather than being forced to Set. union([1,2,3], [3,4]) yields a vector with the shared 3 kept once, preserving first-seen order; union(a, b) with Sets yields a Set. That type difference is the first place people get surprised when they expect a set and receive an array, or vice versa.

If you want to be explicit about the result type, wrap or convert:

For an arbitrary number of sets held in a container, reduce over them:

The init argument matters. If sets is empty and you call reduce(union, sets) without an initial value, Julia raises an error because it has nothing to reduce and no identity element to start from. Supplying init = Set{Int}() (or the appropriate element type) makes the empty case return the empty set, which is the correct union of no sets.

Choosing between union, vcat, and unique

Three constructions look similar and behave differently, and distinguishing them avoids most confusion:

Expression Result with [1,2,3] and [3,4] Duplicates Order
union(x, y) [1, 2, 3, 4] removed first-seen preserved
vcat(x, y) [1, 2, 3, 3, 4] kept concatenation order
unique(vcat(x, y)) [1, 2, 3, 4] removed first-seen preserved

vcat concatenates and keeps duplicates, so it is not a union at all. unique(vcat(x, y)) is functionally close to union(x, y) for vectors and is sometimes written by people who want explicit control, but union already does this and hinges on hashing rather than pairwise scanning, so it is generally the better default. Use vcat when you deliberately want a multiset-like concatenation, for example when counting occurrences across collections.

Testing "is a superset of": issubset and ⊇

If your real question is whether one set contains all elements of another, use issubset or its operator forms. In Julia, issubset(A, B) asks whether every element of A is in B — that is, whether B is a superset of A. The Unicode operators ⊆ and ⊇ mirror this:

Two points cause most errors here. First, the argument order is "is the first argument a subset of the second," so the superset test is expressed as B ⊇ A, not as a function literally named issuperset. There is no issuperset in Base; the relation is symmetric under argument swap. Second, ⊇ and ⊆ are typed with \supe and \sube (or similar LaTeX-style completions in the REPL), and pasting them into an editor without a suitable font can display as boxes — the ASCII issubset call is safer in scripts meant to be portable.

For sets specifically, membership testing is hash-based and fast; for vectors, issubset does membership checks that may scan, so converting large collections to Set first can change performance characteristics substantially. That is a performance consideration, not a correctness one.

Equality versus containment

A set equals another set when each is a subset of the other, and == on Sets captures this: Set([1,2]) == Set([2,1]) is true, because order is irrelevant to set identity. Containment is weaker: Set() ⊆ Set([1,2]) is true while the sets are not equal. A common bug in hand-written superset logic is to test equality where containment was intended, or to compare a Set with a Vector using == and be surprised: Set([1,2]) == [1,2] is false in Julia because the types differ, even though the elements coincide. If you need to compare across collection types, convert explicitly (Set([1,2]) == Set([1,2])) or test both containments.

Element types, Missing, and NaN

union inherits Julia's type promotion. Mixing Int and Float64 yields Float64 elements; mixing Int and String yields Any, which still works but loses type stability and may slow later code. If you know the intended element type, construct the sets with it up front or convert the result:

Two subtleties deserve mention. missing is a valid set element under Julia's three-valued logic, and union treats missing as an ordinary distinct value; but issubset involving missing follows missing-propagation rules, so a containment test can return missing rather than true or false when the answer is indeterminate. Guard with coalesce or ismissing if you require a Boolean. NaN is even trickier: NaN == NaN is false under IEEE floating point, yet Julia's hashing and isequal treat NaN values as equal for Set purposes, so Set([NaN]) has one element and Set([NaN]) ⊆ Set([NaN]) holds. This is consistent within Julia's set model but conflicts with naive == comparisons, so avoid mixing the two styles of equality testing on floating-point sets.

Mutable elements and hashing

Set relies on hash and isequal. If you put mutable objects into a set and then mutate a field that affects their hash, lookups and union behavior can become unreliable — the element is "lost" because its hash bucket changed. The fix is to use immutable elements (structs declared struct, not mutable struct) or to hash on fields that never change. This is a general property of hash-based sets in Julia and in most languages, not a quirk of union; it explains otherwise baffling cases where a set appears to contain an element that membership tests reject.

Practical patterns

A few patterns recur in real code. To build a superset incrementally:

union! mutates its first argument and is the efficient choice when you are accumulating many sets. By contrast, union(superset, s) allocates a fresh set every time, which is fine for a handful of sets but quadratic-ish in allocation for large loops.

To compute the union of the keys of several dictionaries, use union(keys(d1), keys(d2)); keys returns a key set view that participates in union naturally. To deduplicate while preserving a specific priority, remember that first-seen order is preserved for ordered inputs, so the order in which you pass arguments determines the result order for vectors — handy when you want "all tags, primary tag first."

Finally, for very large unions, converting inputs to Set before combining keeps the work hash-based and roughly linear in total elements, whereas unioning many long vectors can be slower because of repeated membership scans. The asymptotics are not a guarantee of speed, since hashing, memory pressure, and element type all matter, but the structural difference between hash-based and scan-based membership is the main lever.

What is unknown here

The query does not specify whether "superset" means the union of multiple sets or the superset relationship between two sets, does not name a Julia version (the union, issubset, and Set APIs described are stable across recent 1.x releases, but operator availability and type-promotion details can shift between versions), and gives no example data. The code above is illustrative and uses ordinary integer and string elements; if your actual data involves custom structs, be sure to define hash and == (or rely on the default field-wise definitions for immutable structs) so that set membership behaves as intended.