Set
A set of distinct keys, typed Set<T>.
@type Set<T>| Function | Summary |
|---|---|
Set.empty |
A set with no elements. |
Set.with_capacity |
An empty set with room for capacity elements, so inserting that many never grows it. |
Set.single |
A set with one element. |
Set.from_list |
A set of the list’s elements, without duplicates, in first-seen order. |
Set.to_list |
The elements, in insertion order. |
Set.len |
The number of elements. |
Set.is_empty |
Whether the set has no elements. |
Set.contains |
Whether element is in the set. |
Set.insert |
Adds an element. |
Set.remove |
Removes an element, if it is there. |
Set.union |
The elements of either set. |
Set.intersection |
The elements of both sets. |
Set.difference |
The elements of first that are not in second. |
Set.walk |
Folds over the elements. |
Set.walk_until |
Folds the elements until f returns :Break(state). |
Set.map |
The set of f of every element. |
Set.join_map |
Unions the sets f returns for each element. |
Set.keep_if |
The elements for which predicate is TRUE. |
Set.drop_if |
The elements for which predicate is FALSE. |
Set.reserve |
The set with room for spare more elements. |
Set.capacity |
How many elements the set holds before its storage must grow. |
Set.release_excess_capacity |
The set with no room beyond its elements. |
Set.empty
Section titled “Set.empty”Set.empty <- function<T: key>() -> Set<T>#: <T: key> fn() -> Set<T>Set.empty <- function()A set with no elements.
Set.empty()#> Set.empty()Set.with_capacity
Section titled “Set.with_capacity”Set.with_capacity <- function<T: key>(capacity: integer) -> Set<T>#: <T: key> fn(capacity: integer) -> Set<T>Set.with_capacity <- function(capacity)An empty set with room for capacity elements, so inserting that many never grows it. The room
is rounded up to a power of two.
Set.capacity(Set.insert(Set.with_capacity(64L), "a"))#> 64LSet.single
Section titled “Set.single”Set.single <- function<T: key>(element: T) -> Set<T>#: <T: key> fn(element: T) -> Set<T>Set.single <- function(element)A set with one element.
Set.single("a")#> Set.from_list(list("a"))Set.from_list
Section titled “Set.from_list”Set.from_list <- function<T: key>(list: list[T]) -> Set<T>#: <T: key> fn(list: list[T]) -> Set<T>Set.from_list <- function(list)A set of the list’s elements, without duplicates, in first-seen order.
Set.from_list(list(2L, 1L, 2L))#> Set.from_list(list(2L, 1L))Set.to_list
Section titled “Set.to_list”Set.to_list <- function<T: key>(set: Set<T>) -> list[T]#: <T: key> fn(set: Set<T>) -> list[T]Set.to_list <- function(set)The elements, in insertion order.
Set.to_list(Set.from_list(list("b", "a")))#> list("b", "a")Set.len
Section titled “Set.len”Set.len <- function<T: key>(set: Set<T>) -> integer#: <T: key> fn(set: Set<T>) -> integerSet.len <- function(set)The number of elements.
Set.len(Set.from_list(list(1L, 1L, 2L)))#> 2LSet.is_empty
Section titled “Set.is_empty”Set.is_empty <- function<T: key>(set: Set<T>) -> logical#: <T: key> fn(set: Set<T>) -> logicalSet.is_empty <- function(set)Whether the set has no elements.
Set.is_empty(Set.empty())#> TRUESet.contains
Section titled “Set.contains”Set.contains <- function<T: key>(set: Set<T>, element: T) -> logical#: <T: key> fn(set: Set<T>, element: T) -> logicalSet.contains <- function(set, element)Whether element is in the set.
Set.contains(Set.from_list(list(1L, 2L)), 2L)#> TRUESet.insert
Section titled “Set.insert”Set.insert <- function<T: key>(set: Set<T>, element: T) -> Set<T>#: <T: key> fn(set: Set<T>, element: T) -> Set<T>Set.insert <- function(set, element)Adds an element.
Set.insert(Set.single(1L), 2L)#> Set.from_list(list(1L, 2L))Set.remove
Section titled “Set.remove”Set.remove <- function<T: key>(set: Set<T>, element: T) -> Set<T>#: <T: key> fn(set: Set<T>, element: T) -> Set<T>Set.remove <- function(set, element)Removes an element, if it is there.
Set.remove(Set.from_list(list(1L, 2L)), 1L)#> Set.from_list(list(2L))Set.union
Section titled “Set.union”Set.union <- function<T: key>(first: Set<T>, second: Set<T>) -> Set<T>#: <T: key> fn(first: Set<T>, second: Set<T>) -> Set<T>Set.union <- function(first, second)The elements of either set.
Set.union(Set.from_list(list(1L, 2L)), Set.from_list(list(2L, 3L)))#> Set.from_list(list(1L, 2L, 3L))Set.intersection
Section titled “Set.intersection”Set.intersection <- function<T: key>(first: Set<T>, second: Set<T>) -> Set<T>#: <T: key> fn(first: Set<T>, second: Set<T>) -> Set<T>Set.intersection <- function(first, second)The elements of both sets.
Set.intersection(Set.from_list(list(1L, 2L)), Set.from_list(list(2L, 3L)))#> Set.from_list(list(2L))Set.difference
Section titled “Set.difference”Set.difference <- function<T: key>(first: Set<T>, second: Set<T>) -> Set<T>#: <T: key> fn(first: Set<T>, second: Set<T>) -> Set<T>Set.difference <- function(first, second)The elements of first that are not in second.
Set.difference(Set.from_list(list(1L, 2L)), Set.from_list(list(2L, 3L)))#> Set.from_list(list(1L))Set.walk
Section titled “Set.walk”Set.walk <- function<T: key, S>(set: Set<T>, state: S, f: fn(S, T) -> S) -> S#: <T: key, S> fn(set: Set<T>, state: S, f: fn(S, T) -> S) -> SSet.walk <- function(set, state, f)Folds over the elements.
Set.walk(Set.from_list(list(1L, 2L, 3L)), 0L, function(total, x) total + x)#> 6LSet.walk_until
Section titled “Set.walk_until”Set.walk_until <- function<T: key, S>(set: Set<T>, state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> S#: <T: key, S> fn(set: Set<T>, state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> SSet.walk_until <- function(set, state, f)Folds the elements until f returns :Break(state).
Set.walk_until(Set.from_list(list(1L, 2L, 3L)), 0L, function(total, x) if (x > 2L) :Break(total) else :Continue(total + x))#> 3LSet.map
Section titled “Set.map”Set.map <- function<A: key, B: key>(set: Set<A>, f: fn(A) -> B) -> Set<B>#: <A: key, B: key> fn(set: Set<A>, f: fn(A) -> B) -> Set<B>Set.map <- function(set, f)The set of f of every element.
Set.map(Set.from_list(list(1L, 2L, 3L)), function(x) x %% 2L)#> Set.from_list(list(1L, 0L))Set.join_map
Section titled “Set.join_map”Set.join_map <- function<A: key, B: key>(set: Set<A>, f: fn(A) -> Set<B>) -> Set<B>#: <A: key, B: key> fn(set: Set<A>, f: fn(A) -> Set<B>) -> Set<B>Set.join_map <- function(set, f)Unions the sets f returns for each element.
Set.join_map(Set.from_list(list(1L, 2L)), function(x) Set.from_list(list(x, x * 10L)))#> Set.from_list(list(1L, 10L, 2L, 20L))Set.keep_if
Section titled “Set.keep_if”Set.keep_if <- function<T: key>(set: Set<T>, predicate: fn(T) -> logical) -> Set<T>#: <T: key> fn(set: Set<T>, predicate: fn(T) -> logical) -> Set<T>Set.keep_if <- function(set, predicate)The elements for which predicate is TRUE.
Set.keep_if(Set.from_list(list(1L, 2L, 3L)), function(x) x > 1L)#> Set.from_list(list(2L, 3L))Set.drop_if
Section titled “Set.drop_if”Set.drop_if <- function<T: key>(set: Set<T>, predicate: fn(T) -> logical) -> Set<T>#: <T: key> fn(set: Set<T>, predicate: fn(T) -> logical) -> Set<T>Set.drop_if <- function(set, predicate)The elements for which predicate is FALSE.
Set.drop_if(Set.from_list(list(1L, 2L, 3L)), function(x) x > 1L)#> Set.from_list(list(1L))Set.reserve
Section titled “Set.reserve”Set.reserve <- function<T: key>(set: Set<T>, spare: integer) -> Set<T>#: <T: key> fn(set: Set<T>, spare: integer) -> Set<T>Set.reserve <- function(set, spare)The set with room for spare more elements.
Set.reserve(Set.single("a"), 1000L)#> Set.from_list(list("a"))Set.capacity
Section titled “Set.capacity”Set.capacity <- function<T: key>(set: Set<T>) -> integer#: <T: key> fn(set: Set<T>) -> integerSet.capacity <- function(set)How many elements the set holds before its storage must grow.
Set.capacity(Set.reserve(Set.single("a"), 9L))#> 10LSet.release_excess_capacity
Section titled “Set.release_excess_capacity”Set.release_excess_capacity <- function<T: key>(set: Set<T>) -> Set<T>#: <T: key> fn(set: Set<T>) -> Set<T>Set.release_excess_capacity <- function(set)The set with no room beyond its elements. An empty set keeps its smallest index, which has room for 4.
Set.capacity(Set.release_excess_capacity(Set.reserve(Set.single("a"), 9L)))#> 1L