data.maps
look up, change, merge and transform maps of keys to values
A map pairs keys with values, written {name: "Ada", age: 36}. These functions look values up, change or merge maps, convert them to and from lists of pairs, and transform every value or key.
Tags: collections
keysthe map’s keys, as a listvaluesthe map’s values, as a listgetthe value under key k, or default if there’s nonehaswhether the map has the key kdelremove key k and its value from the map, changing it, and return the mapmergea new map with every entry of every mapentriesthe map as a list of [key, value] pairs, the same as list(m)from_entriesa map from a list of [key, value] pairs, the reverse of entriesinvertfor a map, swap keys and values, so each value becomes a key (as a string)map_valuesa new map with the same keys and f(value) for every valuefilterkeep only the entries that pass the test f, which is given each key and valuefilter_keyskeep only the entries whose key passes the test f
syntax
Section titled “syntax”1# map + map merges them, and the right side wins on shared keys2{a: 1} + {a: 2, b: 3}{a: 2, b: 3}3# m[k] += v on a missing key starts from 0, an empty string or an empty list, whichever fits v, and a missing map on the way is created4m = {}; m["a"] += 5; m{a: 5}Functions
Section titled “Functions”keys(m: map) -> list
the map’s keys, as a list
1{a: 1, b: 2}.keys["a", "b"]See also values
values
Section titled “values”values(m: map) -> list
the map’s values, as a list
1{a: 1, b: 2}.values[1, 2]See also keys
get(m: map, k: any, default?: any) -> any
the value under key k, or default if there’s none
1{a: 1}.get("a")12{a: 1}.get("b", 0)0See also has
has(m: map, k: any) -> bool
whether the map has the key k
1{a: 1}.has("a")truedel(m: map, k: any) -> map
remove key k and its value from the map, changing it, and return the map
1{a: 1, b: 2}.del("a"){b: 2}See also merge
merge(*maps: map) -> map
a new map with every entry of every map
When maps share a key, the later one’s value wins. Same as a + b
1merge({a: 1, b: 2}, {b: 3}){a: 1, b: 3}2merge({a: 1}, {b: 2}, {a: 3}){a: 3, b: 2}See also del
entries
Section titled “entries”entries(m: map) -> list
the map as a list of [key, value] pairs, the same as list(m)
1{a: 1, b: 2}.entries[["a", 1], ["b", 2]]See also from_entries, list
from_entries
Section titled “from_entries”from_entries(xs: list) -> map
a map from a list of [key, value] pairs, the reverse of entries
If a key repeats, the last one wins
1[["a", 1], ["b", 2]].from_entries{a: 1, b: 2}2zip(["x", "y"], [1, 2]).from_entries{x: 1, y: 2}See also entries
invert
Section titled “invert”invert(m: map) -> map
for a map, swap keys and values, so each value becomes a key (as a string)
1{a: 1, b: 2}.invert{1: "a", 2: "b"}See also entries
map_values
Section titled “map_values”map_values(m: map, f: fn) -> map
a new map with the same keys and f(value) for every value
1{a: 1, b: 2}.map_values(|v| v * 10){a: 10, b: 20}filter
Section titled “filter”filter(m: map, f: fn) -> map
keep only the entries that pass the test f, which is given each key and value
1{a: 1, b: 5}.filter(|k, v| v > 2){b: 5}Tags: searching
See also filter_keys, map_values
filter_keys
Section titled “filter_keys”filter_keys(m: map, f: fn) -> map
keep only the entries whose key passes the test f
1{a: 1, bb: 2}.filter_keys(|k| k.len > 1){bb: 2}Tags: searching
See also filter
More examples
Section titled “More examples”1# sum a map2{a: 1, b: 2}.values.sum33# as [key, value] pairs4{a: 1, b: 2}.list[["a", 1], ["b", 2]]5# defaults with some overridden6{color: "red", size: 1} + {size: 3}{color: "red", size: 3}7# loop over entries8out = []; for [k, v] in {a: 1, b: 2}.entries { out.push("{k}={v}") }; out["a=1", "b=2"]9# count items, starting from an empty map10n = {}; for w in ["a", "b", "a"] { n[w] += 1 }; n{a: 2, b: 1}11# group items under a key12g = {}; for w in ["ant", "bee", "ape"] { g[w[0]] += [w] }; g{a: ["ant", "ape"], b: ["bee"]}13# nested maps appear as you fill them14t = {}; t["x"]["y"] += 1; t{x: {y: 1}}Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.