Map (dictionary) operations. auto-imported.
Create an empty map.
let m = map.new()
Get a value by key. Returns none if the key doesn't exist.
map.get(m, "name")
Get a value by key, returning a default if the key doesn't exist.
map.get_or(m, "name", "unknown")
Return a new map with the key set to value. Immutable — does not modify the original.
let m2 = map.set(m, "name", "Alice")
Check if a key exists in the map.
map.contains(m, "name")
Return a new map with the key removed. Immutable — does not modify the original.
let m2 = map.remove(m, "temp")
Get all keys as a sorted list.
map.keys(m)
Get all values as a list.
map.values(m)
Get the number of key-value pairs in the map.
map.len(m)
Get all key-value pairs as a list of tuples, sorted by key.
map.entries(m)
Merge two maps. Keys in the second map override keys in the first.
map.merge(base, overrides)
Check if the map has no entries.
map.is_empty(m)
Create a map from a list of (key, value) pairs.
map.from_list([("a", 1), ("b", 2)])
Transform all values in the map using a function, keeping keys unchanged.
map.map_values(m, fn(v) => v * 2)
Return a new map containing only entries where the predicate returns true.
map.filter(m, fn(k, v) => v > 0)
Accumulate over all entries with an initial value.
map.fold(scores, 0, (acc, k, v) => acc + v)
Check if any entry satisfies the predicate.
map.any(scores, (k, v) => v >= 90)
Check if all entries satisfy the predicate.
map.all(scores, (k, v) => v > 0)
Count entries that satisfy the predicate.
map.count(scores, (k, v) => v >= 80)
Find the first entry matching the predicate. Returns Option[(K, V)].
map.find(scores, (k, v) => v >= 90)
Update the value at a key using a function. Key must exist.
map.update(scores, "alice", (v) => v + 10)
Insert a key-value pair in place. Requires var binding.
map.insert(m, "name", "Alice")
Remove a key in place. Requires var binding.
map.delete(m, "temp")
Remove all entries in place. Requires var binding.
map.clear(m)