Map Library (Map)
Linked to the map type. Maps stay ordered by key, which is why first/last/at are meaningful, not just get/insert.
Query
Map.len(this: map) -> int
Map.empty(this: map) -> bool
Map.any(this: map) -> bool
Map.contains(this: map, key: unknown) -> bool
Map.keys(this: map) -> set
map-keys.stofPlayground ↗
#[main]
fn main() {
const m = {"a": 1, "b": 2};
pln(str(m.keys()));
}Output
Map.values(this: map) -> list
Access
Map.get(this: map, key: unknown) -> unknown
Map.at(this: map, index: int) -> (unknown, unknown)
The (key, value) pair at a position in sorted order — not a lookup by key.
Map.first(this: map) -> (unknown, unknown)
Map.last(this: map) -> (unknown, unknown)
Modify
Map.insert(this: map, key: unknown, value: unknown) -> unknown
Returns the old value if the key already existed, null otherwise.
map-insert.stofPlayground ↗
#[main]
fn main() {
const m = {"a": 1};
pln(m.insert("a", 3), str(m));
}Output
Map.remove(this: map, key: unknown) -> unknown
map-remove.stofPlayground ↗
#[main]
fn main() {
const m = {"a": 1, "b": 2};
pln(m.remove("b"), str(m));
}Output
Map.pop_first(this: map) -> (unknown, unknown)
map-pop-first.stofPlayground ↗
#[main]
fn main() {
const m = {"a": 1, "b": 2};
pln(m.pop_first(), str(m));
}Output
Map.pop_last(this: map) -> (unknown, unknown)
map-pop-last.stofPlayground ↗
#[main]
fn main() {
const m = {"a": 1, "b": 2};
pln(m.pop_last(), str(m));
}Output
Map.append(this: map, other: map) -> void
map-append.stofPlayground ↗
#[main]
fn main() {
const m = {"a": 1};
m.append({"b": 2});
pln(str(m));
}Output
Map.clear(this: map) -> void
map-clear.stofPlayground ↗
#[main]
fn main() {
const m = {"a": 1};
m.clear();
pln(m.empty());
}Output