Skip to content
ry

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 <- function<T: key>() -> Set<T>

A set with no elements.

Set.empty()
#> Set.empty()

Source

Set.with_capacity <- function<T: key>(capacity: integer) -> Set<T>

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"))
#> 64L

Source

Set.single <- function<T: key>(element: T) -> Set<T>

A set with one element.

Set.single("a")
#> Set.from_list(list("a"))

Source

Set.from_list <- function<T: key>(list: list[T]) -> Set<T>

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))

Source

Set.to_list <- function<T: key>(set: Set<T>) -> list[T]

The elements, in insertion order.

Set.to_list(Set.from_list(list("b", "a")))
#> list("b", "a")

Source

Set.len <- function<T: key>(set: Set<T>) -> integer

The number of elements.

Set.len(Set.from_list(list(1L, 1L, 2L)))
#> 2L

Source

Set.is_empty <- function<T: key>(set: Set<T>) -> logical

Whether the set has no elements.

Set.is_empty(Set.empty())
#> TRUE

Source

Set.contains <- function<T: key>(set: Set<T>, element: T) -> logical

Whether element is in the set.

Set.contains(Set.from_list(list(1L, 2L)), 2L)
#> TRUE

Source

Set.insert <- function<T: key>(set: Set<T>, element: T) -> Set<T>

Adds an element.

Set.insert(Set.single(1L), 2L)
#> Set.from_list(list(1L, 2L))

Source

Set.remove <- function<T: key>(set: Set<T>, element: T) -> Set<T>

Removes an element, if it is there.

Set.remove(Set.from_list(list(1L, 2L)), 1L)
#> Set.from_list(list(2L))

Source

Set.union <- function<T: key>(first: Set<T>, second: Set<T>) -> Set<T>

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))

Source

Set.intersection <- function<T: key>(first: Set<T>, second: Set<T>) -> Set<T>

The elements of both sets.

Set.intersection(Set.from_list(list(1L, 2L)), Set.from_list(list(2L, 3L)))
#> Set.from_list(list(2L))

Source

Set.difference <- function<T: key>(first: Set<T>, second: Set<T>) -> Set<T>

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))

Source

Set.walk <- function<T: key, S>(set: Set<T>, state: S, f: fn(S, T) -> S) -> S

Folds over the elements.

Set.walk(Set.from_list(list(1L, 2L, 3L)), 0L, function(total, x) total + x)
#> 6L

Source

Set.walk_until <- function<T: key, S>(set: Set<T>, state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> S

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))
#> 3L

Source

Set.map <- function<A: key, B: key>(set: Set<A>, f: fn(A) -> B) -> Set<B>

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))

Source

Set.join_map <- function<A: key, B: key>(set: Set<A>, f: fn(A) -> Set<B>) -> Set<B>

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))

Source

Set.keep_if <- function<T: key>(set: Set<T>, predicate: fn(T) -> logical) -> Set<T>

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))

Source

Set.drop_if <- function<T: key>(set: Set<T>, predicate: fn(T) -> logical) -> Set<T>

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))

Source

Set.reserve <- function<T: key>(set: Set<T>, spare: integer) -> Set<T>

The set with room for spare more elements.

Set.reserve(Set.single("a"), 1000L)
#> Set.from_list(list("a"))

Source

Set.capacity <- function<T: key>(set: Set<T>) -> integer

How many elements the set holds before its storage must grow.

Set.capacity(Set.reserve(Set.single("a"), 9L))
#> 10L

Source

Set.release_excess_capacity <- function<T: key>(set: Set<T>) -> Set<T>

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

Source