SagaSaga
Standard Library

Std.Set

Immutable sets backed by Erlang's sets module (version 2).

Functions

new

fun new : Unit -> Set a

Creates an empty set.

from_list

fun from_list : (items: List a) -> Set a where {a: Eq}

Creates a set from a list of elements.

to_list

fun to_list : (set: Set a) -> List a

Returns the elements as a list.

insert

fun insert : (elem: a) -> (set: Set a) -> Set a where {a: Eq}

Inserts an element into the set.

remove

fun remove : (elem: a) -> (set: Set a) -> Set a where {a: Eq}

Removes an element from the set. Returns the set unchanged if not present.

member

fun member : (elem: a) -> (set: Set a) -> Bool where {a: Eq}

Returns True if the element is in the set.

size

fun size : (set: Set a) -> Int

Returns the number of elements in the set.

is_empty

fun is_empty : Set a -> Bool

Returns True if the set has no elements.

union

fun union : (a: Set a) -> (b: Set a) -> Set a where {a: Eq}

Returns the union of two sets.

intersection

fun intersection : (a: Set a) -> (b: Set a) -> Set a where {a: Eq}

Returns the intersection of two sets.

difference

fun difference : (a: Set a) -> (b: Set a) -> Set a where {a: Eq}

Returns elements in the first set but not the second.

symmetric_difference

fun symmetric_difference : (a: Set a) -> (b: Set a) -> Set a where {a: Eq}

Returns elements in either set but not both.

is_subset

fun is_subset : (sub: Set a) -> (super: Set a) -> Bool where {a: Eq}

Returns True if the first set is a subset of the second.

map

fun map : (f: a -> b) -> (set: Set a) -> Set b where {b: Eq}

Applies a function to every element, returning a new set.

filter

fun filter : (pred: a -> Bool) -> (set: Set a) -> Set a

Returns a set containing only elements where the predicate returns True.

fold

fun fold : (f: b -> a -> b) -> (init: b) -> (set: Set a) -> b

Folds over all elements.