Skip to main content

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-len.stofPlayground ↗
#[main]
fn main() {
  const m = {"a": 1, "b": 2};
  pln(m.len());
}
Output

Map::empty(this: map) -> bool​

map-empty.stofPlayground ↗
#[main]
fn main() {
  const m = map();
  pln(m.empty());
}
Output

Map::any(this: map) -> bool​

map-any.stofPlayground ↗
#[main]
fn main() {
  const m = map();
  pln(m.any());
}
Output

Map::contains(this: map, key: unknown) -> bool​

map-contains.stofPlayground ↗
#[main]
fn main() {
  const m = {"a": 1};
  pln(m.contains("a"));
}
Output

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​

map-values.stofPlayground ↗
#[main]
fn main() {
  const m = {"a": 1, "b": 2};
  pln(m.values());
}
Output

Access​

Map::get(this: map, key: unknown) -> unknown​

map-get.stofPlayground ↗
#[main]
fn main() {
  const m = {"a": 1};
  pln(m.get("a"));
}
Output

Map::at(this: map, index: int) -> (unknown, unknown)​

The (key, value) pair at a position in sorted order — not a lookup by key.

map-at.stofPlayground ↗
#[main]
fn main() {
  const m = {"a": 1, "b": 2};
  pln(m.at(1));
}
Output

Map::first(this: map) -> (unknown, unknown)​

map-first.stofPlayground ↗
#[main]
fn main() {
  const m = {"a": 1};
  pln(m.first());
}
Output

Map::last(this: map) -> (unknown, unknown)​

map-last.stofPlayground ↗
#[main]
fn main() {
  const m = {"a": 1, "b": 3};
  pln(m.last());
}
Output

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