Set Library (Set)
Linked to the set type. Ordered, and every value is unique — Types & Units and Collections both touch on this; this page is the complete reference.
Query
Set::len(set: set) -> int
Set::empty(set: set) -> bool
Set::any(set: set) -> bool
Set::contains(set: set, val: unknown) -> bool
Set::is_uniform(set: set) -> bool
Access
Set::at(set: set, index: int) -> unknown
The element at a position in sorted order — null if out of bounds.
Set::first(set: set) -> unknown
The minimum value.
Set::last(set: set) -> unknown
The maximum value.
Modify
Set::insert(set: set, val: unknown) -> bool
Returns whether the value was newly inserted — false if it was already there.
Set::remove(set: set, val: unknown) -> unknown
set-remove.stofPlayground ↗
#[main]
fn main() {
const s = {1, 2, 3};
pln(s.remove(2), ' ', str(s));
}Output
Set::pop_first(set: set) -> unknown
set-pop-first.stofPlayground ↗
#[main]
fn main() {
const s = {1, 2, 3};
pln(s.pop_first(), ' ', str(s));
}Output
Set::pop_last(set: set) -> unknown
set-pop-last.stofPlayground ↗
#[main]
fn main() {
const s = {1, 2, 3};
pln(s.pop_last(), ' ', str(s));
}Output
Set::append(set: set, other: set) -> void
set-append.stofPlayground ↗
#[main]
fn main() {
const s = {1, 2, 3};
s.append({3, 4});
pln(str(s));
}Output
Set::clear(set: set) -> void
Set::split(set: set, val: unknown) -> (set, set)
Splits into everything smaller and everything larger than val — val itself isn't included in either half.
Set::to_uniform(set: set, type: str) -> void
Casts every value to a single type in place.
set-to-uniform.stofPlayground ↗
#[main]
fn main() {
const s = {2000m, 3km};
s.to_uniform("km");
pln(str(s));
}Output
Set Algebra
Set::union(set: set, other: set) -> set
set-union.stofPlayground ↗
#[main]
fn main() {
const s = {1, 2, 3};
const other = {4, 5};
pln(str(s.union(other)));
}Output
Set::intersection(set: set, other: set) -> set
set-intersection.stofPlayground ↗
#[main]
fn main() {
const s = {1, 2, 3};
pln(str(s.intersection({3, 4})));
}Output
Set::difference(set: set, other: set) -> set
Everything in set that isn't in other.
set-difference.stofPlayground ↗
#[main]
fn main() {
const s = {1, 2, 3};
pln(str(s.difference({2, 3})));
}Output
Set::symmetric_difference(set: set, other: set) -> set
Everything in exactly one of the two sets, not both.
set-symmetric-difference.stofPlayground ↗
#[main]
fn main() {
const s = {1, 2, 3};
pln(str(s.symmetric_difference({2, 3, 4})));
}Output
Set::disjoint(set: set, other: set) -> bool
True if the two sets share nothing.
set-disjoint.stofPlayground ↗
#[main]
fn main() {
const s = {1, 2, 3};
const other = {4, 5};
pln(s.disjoint(other));
}Output
Set::subset(set: set, other: set) -> bool
True if every value in set is also in other.
set-subset.stofPlayground ↗
#[main]
fn main() {
const s = {2, 3};
const other = {2, 3, 4};
pln(s.subset(other));
}Output
Set::superset(set: set, other: set) -> bool
True if every value in other is also in set — the reverse of subset.
set-superset.stofPlayground ↗
#[main]
fn main() {
const s = {2, 3};
const other = {2, 3, 4};
pln(other.superset(s));
}Output