Skip to content

std.map - ZZ

Pure-ZZ dict helpers over {K: V}: safe lookup, projections, merge. Dicts are insertion-ordered with O(n) lookup; the API is stable so a hashed implementation can drop in later without breaking callers.

import std.map

std.map provides safe, fallible-free lookups and projections over dicts. No runtime errors on missing keys — use get_or for defaults. Both {str: int} and {str: str} variants exist (get_str, keys_str, values_str, merge_str). Ideal for configuration, lookup tables, and small-to-medium keyed data.

Dicts are immutable values: map.merge, map.remove return a new dict; the original is unchanged. Lookup is O(n) (linear scan) — intentional for simplicity and stable iteration order. A future hashed implementation can replace the backing store without changing the API.

import std.map
d := {"a": 1, "b": 2}
map.get_or(d, "z", 99) // 99, no error
map.has(d, "a") // true
map.keys(d) // ["a", "b"]
map.values(d) // [1, 2]
map.merge(d, {"c": 3}) // {"a":1,"b":2,"c":3}
map.remove(d, "a") // {"b":2}

12 entries. Signatures come from the compiler’s own FuncSig table, so they match the runtime exactly; descriptions come from the module guide.

Function Signature Description
std.map.get_or get_or(d: {str: int}, key: str, default: int) -> int Value or default
std.map.get_str get_str(d: {str: str}, key: str, default: str) -> str {str:str} get-or-default
std.map.has has(d: {str: int}, key: str) -> bool Membership (no error on missing)
std.map.is_empty is_empty(d: {str: int}) -> bool Empty check
std.map.keys keys(d: {str: int}) -> [str] Key array (insertion order)
std.map.keys_str keys_str(d: {str: str}) -> [str] {str:str} keys
std.map.len len(d: {str: int}) -> int Size
std.map.merge merge(a: {str: int}, b: {str: int}) -> {str: int} Right-wins union
std.map.merge_str merge_str(a: {str: str}, b: {str: str}) -> {str: str} {str:str} right-wins union
std.map.remove remove(d: {str: int}, key: str) -> {str: int} Copy without key
std.map.values values(d: {str: int}) -> [int] Value array
std.map.values_str values_str(d: {str: str}) -> [str] {str:str} values
  • std.json — Parse, stringify and read individual values out of JSON.
  • std.set — Arrays with uniqueness: membership, union, intersection and difference.
  • std.dec — Exact decimal arithmetic carried as strings, so money never becomes a float.
  • std.csv — An RFC 4180 subset: read rows, write rows, handle quotes and commas.
  • std.property — Seeded generators and shrinking for property-based tests.

Full index: API reference · Standard library