Skip to content

set

The set module provides functions for working with Set[A] collections of unique values. It is auto-imported — no import statement needed.

FunctionSignatureDescription
new() -> Set[A]Create an empty set
from_list(List[A]) -> Set[A]Create set from list
FunctionSignatureDescription
contains(Set[A], A) -> BoolCheck membership
len(Set[A]) -> IntNumber of elements
is_empty(Set[A]) -> BoolEmpty check
to_list(Set[A]) -> List[A]Convert to list
FunctionSignatureDescription
insert(Set[A], A) -> Set[A]Add value (returns new set)
remove(Set[A], A) -> Set[A]Remove value (returns new set)
FunctionSignatureDescription
union(Set[A], Set[A]) -> Set[A]Union of two sets
intersection(Set[A], Set[A]) -> Set[A]Intersection
difference(Set[A], Set[A]) -> Set[A]Elements in a not in b
symmetric_difference(Set[A], Set[A]) -> Set[A]Elements in either but not both
is_subset(Set[A], Set[A]) -> BoolCheck if a is subset of b
is_disjoint(Set[A], Set[A]) -> BoolCheck if no common elements
FunctionSignatureDescription
filter(Set[A], Fn[A] -> Bool) -> Set[A]Keep matching elements
map(Set[A], Fn[A] -> B) -> Set[B]Transform elements
fold(Set[A], B, Fn[B, A] -> B) -> BAccumulate over elements
each(Set[A], Fn[A] -> Unit) -> UnitSide effect per element
any(Set[A], Fn[A] -> Bool) -> BoolAny element matches
all(Set[A], Fn[A] -> Bool) -> BoolAll elements match
let a = set.from_list([1, 2, 3])
let b = set.from_list([2, 3, 4])
set.union(a, b) // {1, 2, 3, 4}
set.intersection(a, b) // {2, 3}
set.difference(a, b) // {1}
set.contains(a, 2) // => true
set.is_subset(a, b) // => false