Set operations. auto-imported.
Create an empty set.
set.new()
Create a set from a list of values.
set.from_list([1, 2, 3])
Add a value to the set. Returns a new set.
set.insert(s, 42)
Remove a value from the set. Returns a new set.
set.remove(s, 42)
Check if a value is in the set.
set.contains(s, 42)
Return the number of elements.
set.len(s)
Check if the set has no elements.
set.is_empty(s)
Convert a set to a list.
set.to_list(s)
Return the union of two sets.
set.union(a, b)
Return the intersection of two sets.
set.intersection(a, b)
Return elements in a that are not in b.
set.difference(a, b)
Return elements in either set but not both.
set.symmetric_difference(a, b)
Check if all elements of a are in b.
set.is_subset(a, b)
Check if two sets have no elements in common.
set.is_disjoint(a, b)
Keep elements that satisfy a predicate.
set.filter(s, fn(x) => x > 2)
Apply a function to each element, returning a new set.
set.map(s, fn(x) => x * 2)
Reduce a set with an initial accumulator.
set.fold(s, 0, fn(acc, x) => acc + x)
Check if any element satisfies a predicate.
set.any(s, fn(x) => x > 2)
Check if all elements satisfy a predicate.
set.all(s, fn(x) => x > 0)