Set
Standard library for set operations.
Functions in this module operate on type Set<A>
, which represents a hash
set (using a hash array mapped trie) with O(log n)
put()
,
contains?()
, and delete()
. Literal sets can be
created with the syntax #[a, b, ...]
, where a
, b
, etc. are elements.
To import all names from this module, use:
import Set (*)
With no import, you can still access anything with the prefix Set.
, like Set.intersect
.
Index
Name | Type | Description |
---|---|---|
Set<A> -> Int | Returns the length of | |
Set<A> -> Bool | Returns whether | |
(Set<A>, Set<A>) -> Set<A> | Concatenates | |
[Set<A>] -> Set<A> | Concatenates all elements in the list | |
(Set<A>, A -> B) -> Set<B> | Calls | |
(Set<A>, Set<A>) -> Set<A> | Returns a new set with elements that are both in set | |
(Set<A>, Set<A>) -> Set<A> | Merges sets | |
(Set<A>, Set<A>) -> Set<A> | Returns a new set with elements that are in set | |
(Set<A>, Set<A>) -> Bool | Returns true if | |
(Set<A>, Set<A>) -> Bool | Returns true if | |
(Set<A>, F, (F, A) -> F) -> F | Computes a single value by applying the combining function | |
(Set<A>, A -> Bool) -> Set<A> | Calls | |
(Set<A>, A -> Bool) -> Option<A> | Returns the first element in | |
(Set<A>, A -> Option<B>) -> Set<B> | Calls | |
(Set<A>, F, (F, A) -> (F, B)) -> (F, Set<B>) | Computes a new collection and a single value by applying the combining
function | |
(Set<A>, A) -> Set<A> | Puts | |
(Set<A>, A) -> Set<A> | Removes | |
(Set<A>, A) -> Bool | Returns true if | |
(Set<A>, A -> Bool) -> Bool | Calls | |
(Set<A>, A -> Bool) -> Bool | Calls | |
Set<A> -> [A] | Converts | |
Set<(K, V)> -> Map<K, V> | Converts |
Functions
intersect : (Set<A>, Set<A>) -> Set<A> intersect(a, b)
Returns a new set with elements that are both in set a
and in set b
.
assert intersect(#[1, 3, 5], #[3, 5, 6]) == #[3, 5] assert intersect(#['a', 'b'], #['c', 'd', 'e', 'f']) == #[] assert intersect(#[], #["hey", "hello"]) == #[]
union : (Set<A>, Set<A>) -> Set<A> union(a, b)
Merges sets a
and b
, returning a new set. This is an alias for
concat()
and is equivalent to a ++ b
.
assert union(#[1, 3, 5], #[3, 5, 6]) == #[1, 3, 5, 6] assert union(#['a', 'b'], #['c', 'd', 'e', 'f']) == #['a', 'b', 'c', 'd', 'e', 'f'] assert union(#[], #["hey", "hello"]) == #["hey", "hello"]
subtract : (Set<A>, Set<A>) -> Set<A> subtract(a, b)
Returns a new set with elements that are in set a
, but not in set b
. This
is equivalent to a -- b
.
assert subtract(#[1, 3, 5], #[3, 5, 6]) == #[1] assert subtract(#[3, 5, 6], #[1, 3, 5]) == #[6] assert subtract(#[], #["hey", "hello"]) == #[] assert subtract(#["hey", "hello"], #[]) == #["hey", "hello"]
subset? : (Set<A>, Set<A>) -> Bool subset?(a, b)
Returns true if b
is a subset of a
; that is, if a
contains every
element in b
. Note that if a == b
, this function returns true.
assert subset?(#[3, 5, 6], #[3, 5]) assert !subset?(#[3, 5, 6], #[1, 3, 5]) assert !subset?(#[3, 5], #[3, 5, 6]) assert subset?(#["hey", "hello"], #[])
disjoint? : (Set<A>, Set<A>) -> Bool disjoint?(a, b)
Returns true if a
and b
share no elements in common.
assert disjoint?(#[1, 3, 5], #[2, 4, 6]) assert !disjoint?(#[1, 3, 5], #[2, 5]) assert disjoint?(#[], #["hey", "hello"])
Implementations
impl Sized for Set<A>
The following functions are from the Sized
interface.
length : Set<A> -> Int length(sized)
Returns the length of sized
. See the full description in the Sized
interface.
empty? : Set<A> -> Bool empty?(sized)
Returns whether sized
is empty. See the full description in the Sized
interface.
impl Concat for Set<A>
The following functions are from the Concat
interface.
concat : (Set<A>, Set<A>) -> Set<A> concat(a, b)
Concatenates a
and b
together, equivalent to a ++ b
. See the full description in the Concat
interface.
concat_all : [Set<A>] -> Set<A> concat_all(l)
Concatenates all elements in the list l
together. See the full description in the Concat
interface.
impl Mappable for Set
The following functions are from the Mappable
interface.
map : (Set<A>, A -> B) -> Set<B> map(container, f)
Calls f
for each element in container
, collecting the results into
a new container. See the full description in the Mappable
interface.
impl Collection for Set
The following functions are from the Collection
interface.
fold : (Set<A>, F, (F, A) -> F) -> F fold(collection, init, f)
Computes a single value by applying the combining function f
to each
element of the given collection
, starting with the initial value init
. See the full description in the Collection
interface.
filter : (Set<A>, A -> Bool) -> Set<A> filter(collection, f)
Calls f
for each element in collection
, returning a new collection
that only contains the elements for which f
returns true. See the full description in the Collection
interface.
find : (Set<A>, A -> Bool) -> Option<A> find(collection, f)
Returns the first element in collection
for which f
returns true. See the full description in the Collection
interface.
filter_map : (Set<A>, A -> Option<B>) -> Set<B> filter_map(collection, f)
Calls f
for each element in collection
, returning a new collection
that contains every e
such that f
returned Some(e)
. See the full description in the Collection
interface.
fold_map : (Set<A>, F, (F, A) -> (F, B)) -> (F, Set<B>) fold_map(collection, init, f)
Computes a new collection and a single value by applying the combining
function f
to each element of the given collection
, starting with the
initial value init
. See the full description in the Collection
interface.
put : (Set<A>, A) -> Set<A> put(collection, elem)
Puts elem
into collection
, returning a new collection. See the full description in the Collection
interface.
delete : (Set<A>, A) -> Set<A> delete(collection, elem)
Removes elem
from collection
, returning a new collection. See the full description in the Collection
interface.
contains? : (Set<A>, A) -> Bool contains?(collection, elem)
Returns true if collection
contains elem
. See the full description in the Collection
interface.
all? : (Set<A>, A -> Bool) -> Bool all?(collection, f)
Calls f
for each element in collection
, and returns true if f
returns true for every element. See the full description in the Collection
interface.
any? : (Set<A>, A -> Bool) -> Bool any?(collection, f)
Calls f
for each element in collection
, and returns true if f
returns true for at least one element. See the full description in the Collection
interface.
impl ToList for Set
The following functions are from the ToList
interface.
to_list : Set<A> -> [A] to_list(a)
Converts a
to a list. See the full description in the ToList
interface.
impl ToMap for Set