data.maps
keys, values, lookups, merging and transforming maps
Example results generated on 2026-10-08. Ones using
now,todayor randomness will differ when you run them: press Run on any example to run it in your browser, after editing it if you like.
operators
# map + map
{a: 1} + {a: 2, b: 3}
# → {a: 2, b: 3}
Functions
| function | description |
|---|---|
keys(m: map) | list of map keys |
values(m: map) | list of map values |
get(m: map, k: any, default?: any) | value at k, or default (nil if not given) |
has(m: map, k: any) | true if m has the key k |
del(m: map, k: any) | remove k in place and return the map |
merge(a: map, b: map) | new map with both; b wins on shared keys, same as a + b |
entries(m: map) | [key, value] pairs, same as list(m) |
from_entries(xs: list) | map from [key, value] pairs; later keys win |
invert(m: map) / invert(c: str|list) | swap a map’s keys and values (values become string keys), or the opposite color |
map_values(m: map, f: fn) | apply f to every value, keeping keys |
filter_keys(m: map, f: fn) | keep entries whose key f is truthy for |
keys
keys(m: map): list of map keys
{a: 1, b: 2}.keys
# → ["a", "b"]
See also: values
values
values(m: map): list of map values
{a: 1, b: 2}.values
# → [1, 2]
See also: keys
get
get(m: map, k: any, default?: any): value at k, or default (nil if not given)
{a: 1}.get("a")
# → 1
{a: 1}.get("b", 0)
# → 0
See also: has
has
has(m: map, k: any): true if m has the key k
{a: 1}.has("a")
# → true
del
del(m: map, k: any): remove k in place and return the map
{a: 1, b: 2}.del("a")
# → {b: 2}
See also: merge
merge
merge(a: map, b: map): new map with both; b wins on shared keys, same as a + b
merge({a: 1, b: 2}, {b: 3})
# → {a: 1, b: 3}
See also: del
entries
entries(m: map): [key, value] pairs, same as list(m)
{a: 1, b: 2}.entries
# → [["a", 1], ["b", 2]]
See also: from_entries, list
from_entries
from_entries(xs: list): map from [key, value] pairs; later keys win
[["a", 1], ["b", 2]].from_entries
# → {a: 1, b: 2}
zip(["x", "y"], [1, 2]).from_entries
# → {x: 1, y: 2}
See also: entries
invert
invert(m: map) / invert(c: str|list): swap a map’s keys and values (values become string keys), or the opposite color
{a: 1, b: 2}.invert
# → {1: "a", 2: "b"}
invert("navy")
# → "#ffff7f"
map_values
map_values(m: map, f: fn): apply f to every value, keeping keys
{a: 1, b: 2}.map_values(|v| v * 10)
# → {a: 10, b: 20}
filter_keys
filter_keys(m: map, f: fn): keep entries whose key f is truthy for
{a: 1, bb: 2}.filter_keys(|k| k.len > 1)
# → {bb: 2}
See also: filter
More examples
maps
# sum a map
{a: 1, b: 2}.values.sum
# → 3
# as [key, value] pairs
{a: 1, b: 2}.list
# → [["a", 1], ["b", 2]]
# defaults, overridden
{color: "red", size: 1} + {size: 3}
# → {color: "red", size: 3}
# loop over entries
out = []; for [k, v] in {a: 1, b: 2}.entries { out.push("{k}={v}") }; out
# → ["a=1", "b=2"]