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-len.stof
#[main]
fn main() {
const s = {1, 2, 3};
pln(s.len());
}Output
Set.empty(set: set) -> bool
set-empty.stof
#[main]
fn main() {
const s = {1, 2, 3};
pln(s.empty());
}Output
Set.any(set: set) -> bool
set-any.stof
#[main]
fn main() {
const s = {1, 2, 3};
pln(s.any());
}Output
Set.contains(set: set, val: unknown) -> bool
set-contains.stof
#[main]
fn main() {
const s = {1, 2, 3};
pln(s.contains(3));
}Output
Set.is_uniform(set: set) -> str
set-is-uniform.stof
#[main]
fn main() {
const s = {2, 3};
pln(s.is_uniform());
}Output
Access
Set.at(set: set, index: int) -> unknown
The element at a position in sorted order — null if out of bounds.
set-at.stof
#[main]
fn main() {
const s = {1, 2, 3};
pln(s[1]);
}Output
Set.first(set: set) -> unknown
The minimum value.
set-first.stof
#[main]
fn main() {
const s = {1, 2, 3};
pln(s.first());
}Output
Set.last(set: set) -> unknown
The maximum value.
set-last.stof
#[main]
fn main() {
const s = {1, 2, 3};
pln(s.last());
}Output
Modify
Set.insert(set: set, val: unknown) -> bool
Returns whether the value was newly inserted — false if it was already there.
set-insert.stof
#[main]
fn main() {
const s = {1, 2};
pln(s.insert(3));
}Output
Set.remove(set: set, val: unknown) -> unknown
set-remove.stof
#[main]
fn main() {
const s = {1, 2, 3};
pln(s.remove(2), str(s));
}Output
Set.pop_first(set: set) -> unknown
set-pop-first.stof
#[main]
fn main() {
const s = {1, 2, 3};
pln(s.pop_first(), str(s));
}Output
Set.pop_last(set: set) -> unknown
set-pop-last.stof
#[main]
fn main() {
const s = {1, 2, 3};
pln(s.pop_last(), str(s));
}Output
Set.append(set: set, other: set) -> void
set-append.stof
#[main]
fn main() {
const s = {1, 2, 3};
s.append({3, 4});
pln(str(s));
}Output
Set.clear(set: set) -> void
set-clear.stof
#[main]
fn main() {
const s = {1, 2, 3};
s.clear();
pln(str(s));
}Output
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-split.stof
#[main]
fn main() {
const s = {1, 2, 3};
pln(str(s.split(2)));
}Output
Set.to_uniform(set: set, type: str) -> void
Casts every value to a single type in place.
set-to-uniform.stof
#[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.stof
#[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.stof
#[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.stof
#[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.stof
#[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.stof
#[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.stof
#[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.stof
#[main]
fn main() {
const s = {2, 3};
const other = {2, 3, 4};
pln(other.superset(s));
}Output