githubEdit

Set Library (Set)

Linked with the "set" type.

Example Usage

#[main]
fn main() {
    const a = {1, 2, 3};
    assert_eq(a.len(), 3);
    assert_eq(Set.len(a), 3);
}

Set.any(set: set) -> bool

Does this set contain any values?

const set = {1, 2, 3};
assert(set.any());

Set.append(set: set, other: set) -> void

Append another set to this one.

const set = {1, 2, 3};
set.append({3, 4});
assert_eq(set, {1, 2, 3, 4});

Set.at(set: set, index: int) -> unknown

Return the Nth (index) element in this ordered set, or null if the index is out of bounds.

Set.clear(set: set) -> void

Clear all values from the set.

Set.contains(set: set, val: unknown) -> bool

Returns true if the set contains the value.

Set.difference(set: set, other: set) -> set

Perform a difference between two sets, returning a new set (everything in this set that is not in other).

Set.disjoint(set: set, other: set) -> bool

Returns true if there is no overlap between the two sets (empty intersection).

Set.empty(set: set) -> bool

Is this set empty?

Set.first(set: set) -> unknown

Return the first (minimum) value in the set, or null if the set is empty.

Set.insert(set: set, val: unknown) -> bool

Insert the value into the set, returning true if the value was not previously in the set (newly inserted).

Set.intersection(set: set, other: set) -> set

Perform an intersection between two sets, returning a new set (only elements found in both sets).

Set.is_uniform(set: set) -> bool

Returns true if all values in this set are of the same specific type.

Set.last(set: set) -> unknown

Return the last (maximum) value in the set, or null if the set is empty.

Set.len(set: set) -> int

Return the size of this set (cardinality).

Set.pop_first(set: set) -> unknown

Remove and return the first (minimum) value in the set.

Set.pop_last(set: set) -> unknown

Remove and return the last (maxiumum) value in the set.

Set.remove(set: set, val: unknown) -> unknown

Remove and return the value if found in the set, otherwise null.

Set.split(set: set, val: unknown) -> (set, set)

Split the set into a smaller set (left) and larger set (right) at the given value (not included in resulting sets).

Set.subset(set: set, other: set) -> bool

Returns true if all values in this set exist within another set.

Set.superset(set: set, other: set) -> bool

Returns true if all values in another set exist within this set.

Set.symmetric_difference(set: set, other: set) -> set

Perform a symmetric difference between two sets, returning a new set (values in this set that do not exist in other unioned with the values in other that do not exist in this set).

Set.to_uniform(set: set, type: str) -> void

Try casting all set values to a single type. Type parameter is a string, just like you'd specify a type in Stof.

Set.union(set: set, other: set) -> set

Union two sets, returning a new set.

Last updated