set
The set module is auto-imported — no import statement needed.
Functions
Section titled “Functions”| Function | Signature | Description |
|---|---|---|
new | () -> Set[A] | Create an empty set. |
from_list | (List[A]) -> Set[A] | Create a set from a list of values. |
insert | (Set[A], A) -> Set[A] | Add a value to the set. Returns a new set. |
remove | (Set[A], A) -> Set[A] | Remove a value from the set. Returns a new set. |
contains | (Set[A], A) -> Bool | Check if a value is in the set. |
len | (Set[A]) -> Int | Return the number of elements. |
is_empty | (Set[A]) -> Bool | Check if the set has no elements. |
to_list | (Set[A]) -> List[A] | Convert a set to a list. |
union | (Set[A], Set[A]) -> Set[A] | Return the union of two sets. |
intersection | (Set[A], Set[A]) -> Set[A] | Return the intersection of two sets. |
difference | (Set[A], Set[A]) -> Set[A] | Return elements in a that are not in b. |
symmetric_difference | (Set[A], Set[A]) -> Set[A] | Return elements in either set but not both. |
is_subset | (Set[A], Set[A]) -> Bool | Check if all elements of a are in b. |
is_disjoint | (Set[A], Set[A]) -> Bool | Check if two sets have no elements in common. |
filter | (Set[A], Fn[A] -> Bool) -> Set[A] | Keep elements that satisfy a predicate. |
map | (Set[A], Fn[A] -> B) -> Set[B] | Apply a function to each element, returning a new set. |
fold | (Set[A], B, Fn[B, A] -> B) -> B | Reduce a set with an initial accumulator. |
any | (Set[A], Fn[A] -> Bool) -> Bool | Check if any element satisfies a predicate. |
all | (Set[A], Fn[A] -> Bool) -> Bool | Check if all elements satisfy a predicate. |
Reference
Section titled “Reference”set.new() -> Set[A]
Section titled “set.new() -> Set[A]”Create an empty set.
set.new()set.from_list(xs: List[A]) -> Set[A]
Section titled “set.from_list(xs: List[A]) -> Set[A]”Create a set from a list of values.
set.from_list([1, 2, 3])set.insert(s: Set[A], value: A) -> Set[A]
Section titled “set.insert(s: Set[A], value: A) -> Set[A]”Add a value to the set. Returns a new set.
set.insert(s, 42)set.remove(s: Set[A], value: A) -> Set[A]
Section titled “set.remove(s: Set[A], value: A) -> Set[A]”Remove a value from the set. Returns a new set.
set.remove(s, 42)set.contains(s: Set[A], value: A) -> Bool
Section titled “set.contains(s: Set[A], value: A) -> Bool”Check if a value is in the set.
set.contains(s, 42)set.len(s: Set[A]) -> Int
Section titled “set.len(s: Set[A]) -> Int”Return the number of elements.
set.len(s)set.is_empty(s: Set[A]) -> Bool
Section titled “set.is_empty(s: Set[A]) -> Bool”Check if the set has no elements.
set.is_empty(s)set.to_list(s: Set[A]) -> List[A]
Section titled “set.to_list(s: Set[A]) -> List[A]”Convert a set to a list.
set.to_list(s)set.union(a: Set[A], b: Set[A]) -> Set[A]
Section titled “set.union(a: Set[A], b: Set[A]) -> Set[A]”Return the union of two sets.
set.union(a, b)set.intersection(a: Set[A], b: Set[A]) -> Set[A]
Section titled “set.intersection(a: Set[A], b: Set[A]) -> Set[A]”Return the intersection of two sets.
set.intersection(a, b)set.difference(a: Set[A], b: Set[A]) -> Set[A]
Section titled “set.difference(a: Set[A], b: Set[A]) -> Set[A]”Return elements in a that are not in b.
set.difference(a, b)set.symmetric_difference(a: Set[A], b: Set[A]) -> Set[A]
Section titled “set.symmetric_difference(a: Set[A], b: Set[A]) -> Set[A]”Return elements in either set but not both.
set.symmetric_difference(a, b)set.is_subset(a: Set[A], b: Set[A]) -> Bool
Section titled “set.is_subset(a: Set[A], b: Set[A]) -> Bool”Check if all elements of a are in b.
set.is_subset(a, b)set.is_disjoint(a: Set[A], b: Set[A]) -> Bool
Section titled “set.is_disjoint(a: Set[A], b: Set[A]) -> Bool”Check if two sets have no elements in common.
set.is_disjoint(a, b)set.filter(s: Set[A], f: Fn[A] -> Bool) -> Set[A]
Section titled “set.filter(s: Set[A], f: Fn[A] -> Bool) -> Set[A]”Keep elements that satisfy a predicate.
set.filter(s, fn(x) => x > 2)set.map(s: Set[A], f: Fn[A] -> B) -> Set[B]
Section titled “set.map(s: Set[A], f: Fn[A] -> B) -> Set[B]”Apply a function to each element, returning a new set.
set.map(s, fn(x) => x * 2)set.fold(s: Set[A], init: B, f: Fn[B, A] -> B) -> B
Section titled “set.fold(s: Set[A], init: B, f: Fn[B, A] -> B) -> B”Reduce a set with an initial accumulator.
set.fold(s, 0, fn(acc, x) => acc + x)set.any(s: Set[A], f: Fn[A] -> Bool) -> Bool
Section titled “set.any(s: Set[A], f: Fn[A] -> Bool) -> Bool”Check if any element satisfies a predicate.
set.any(s, fn(x) => x > 2)set.all(s: Set[A], f: Fn[A] -> Bool) -> Bool
Section titled “set.all(s: Set[A], f: Fn[A] -> Bool) -> Bool”Check if all elements satisfy a predicate.
set.all(s, fn(x) => x > 0)