Skip to content

Set

Immutable unique collection operations. All functions return new sets — they never mutate the original.

FunctionSignatureDescription
Set.empty() -> Set<T>Create an empty set
Set.fromArrayArray<T> -> Set<T>Create a set from an array
Set.toArraySet<T> -> Array<T>Convert a set to an array
Set.addSet<T>, T -> Set<T>Add an element
Set.removeSet<T>, T -> Set<T>Remove an element
Set.hasSet<T>, T -> booleanCheck if an element exists
Set.sizeSet<T> -> numberNumber of elements
Set.isEmptySet<T> -> booleanTrue if set has no elements
Set.unionSet<T>, Set<T> -> Set<T>Union of two sets
Set.intersectSet<T>, Set<T> -> Set<T>Intersection of two sets
Set.diffSet<T>, Set<T> -> Set<T>Difference (elements in first but not second)
// Create a set from an array
const tags = Set.fromArray(["urgent", "bug", "frontend"])
// All operations are immutable
const updated = tags
|> Set.add("backend")
|> Set.remove("frontend")
// Check membership
const isUrgent = tags |> Set.has("urgent") // true
// Set operations
const teamA = Set.fromArray(["alice", "bob", "carol"])
const teamB = Set.fromArray(["bob", "carol", "dave"])
const everyone = Set.union(teamA, teamB) // {"alice", "bob", "carol", "dave"}
const overlap = Set.intersect(teamA, teamB) // {"bob", "carol"}
const onlyA = Set.diff(teamA, teamB) // {"alice"}
// Convert back to array
const tagList = tags |> Set.toArray