Skip to content

map

The map module is auto-imported — no import statement needed.

FunctionSignatureDescription
new() -> Map[K, V]Create an empty map.
get(Map[K, V], K) -> Option[V]Get a value by key. Returns none if the key doesn’t exist.
get_or(Map[K, V], K, V) -> VGet a value by key, returning a default if the key doesn’t exist.
set(Map[K, V], K, V) -> Map[K, V]Return a new map with the key set to value. Immutable — does not modify the original.
contains(Map[K, V], K) -> BoolCheck if a key exists in the map.
remove(Map[K, V], K) -> Map[K, V]Return a new map with the key removed. Immutable — does not modify the original.
keys(Map[K, V]) -> List[K]Get all keys as a sorted list.
values(Map[K, V]) -> List[V]Get all values as a list.
len(Map[K, V]) -> IntGet the number of key-value pairs in the map.
entries(Map[K, V]) -> List[(K, V)]Get all key-value pairs as a list of tuples, sorted by key.
merge(Map[K, V], Map[K, V]) -> Map[K, V]Merge two maps. Keys in the second map override keys in the first.
is_empty(Map[K, V]) -> BoolCheck if the map has no entries.
from_list(List[(K, V)]) -> Map[K, V]Create a map from a list of (key, value) pairs.
map(Map[K, V], Fn[V] -> B) -> Map[K, B]Transform all values in the map using a function, keeping keys unchanged.
filter(Map[K, V], Fn[K, V] -> Bool) -> Map[K, V]Return a new map containing only entries where the predicate returns true.
fold(Map[K, V], A, Fn[A, K, V] -> A) -> AAccumulate over all entries with an initial value.
any(Map[K, V], Fn[K, V] -> Bool) -> BoolCheck if any entry satisfies the predicate.
all(Map[K, V], Fn[K, V] -> Bool) -> BoolCheck if all entries satisfy the predicate.
count(Map[K, V], Fn[K, V] -> Bool) -> IntCount entries that satisfy the predicate.
find(Map[K, V], Fn[K, V] -> Bool) -> Option[(K, V)]Find the first entry matching the predicate. Returns Option[(K, V)].
update(Map[K, V], K, Fn[V] -> V) -> Map[K, V]Update the value at a key using a function. Key must exist.
insert(Map[K, V], K, V) -> UnitInsert a key-value pair in place. Requires var binding.
delete(Map[K, V], K) -> UnitRemove a key in place. Requires var binding.
clear(Map[K, V]) -> UnitRemove all entries in place. Requires var binding.

Create an empty map.

let m = map.new()

map.get(m: Map[K, V], key: K) -> Option[V]

Section titled “map.get(m: Map[K, V], key: K) -> Option[V]”

Get a value by key. Returns none if the key doesn’t exist.

map.get(m, "name")

map.get_or(m: Map[K, V], key: K, default: V) -> V

Section titled “map.get_or(m: Map[K, V], key: K, default: V) -> V”

Get a value by key, returning a default if the key doesn’t exist.

map.get_or(m, "name", "unknown")

map.set(m: Map[K, V], key: K, value: V) -> Map[K, V]

Section titled “map.set(m: Map[K, V], key: K, value: V) -> Map[K, V]”

Return a new map with the key set to value. Immutable — does not modify the original.

let m2 = map.set(m, "name", "Alice")

map.contains(m: Map[K, V], key: K) -> Bool

Section titled “map.contains(m: Map[K, V], key: K) -> Bool”

Check if a key exists in the map.

map.contains(m, "name")

map.remove(m: Map[K, V], key: K) -> Map[K, V]

Section titled “map.remove(m: Map[K, V], key: K) -> Map[K, V]”

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)

map.merge(a: Map[K, V], b: Map[K, V]) -> Map[K, V]

Section titled “map.merge(a: Map[K, V], b: Map[K, V]) -> Map[K, V]”

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)

map.from_list(pairs: List[(K, V)]) -> Map[K, V]

Section titled “map.from_list(pairs: List[(K, V)]) -> Map[K, V]”

Create a map from a list of (key, value) pairs.

map.from_list([("a", 1), ("b", 2)])

map.map(m: Map[K, V], f: Fn[V] -> B) -> Map[K, B]

Section titled “map.map(m: Map[K, V], f: Fn[V] -> B) -> Map[K, B]”

Transform all values in the map using a function, keeping keys unchanged.

map.map_values(m, fn(v) => v * 2)

map.filter(m: Map[K, V], f: Fn[K, V] -> Bool) -> Map[K, V]

Section titled “map.filter(m: Map[K, V], f: Fn[K, V] -> Bool) -> Map[K, V]”

Return a new map containing only entries where the predicate returns true.

map.filter(m, fn(k, v) => v > 0)

map.fold(m: Map[K, V], init: A, f: Fn[A, K, V] -> A) -> A

Section titled “map.fold(m: Map[K, V], init: A, f: Fn[A, K, V] -> A) -> A”

Accumulate over all entries with an initial value.

map.fold(scores, 0, (acc, k, v) => acc + v)

map.any(m: Map[K, V], f: Fn[K, V] -> Bool) -> Bool

Section titled “map.any(m: Map[K, V], f: Fn[K, V] -> Bool) -> Bool”

Check if any entry satisfies the predicate.

map.any(scores, (k, v) => v >= 90)

map.all(m: Map[K, V], f: Fn[K, V] -> Bool) -> Bool

Section titled “map.all(m: Map[K, V], f: Fn[K, V] -> Bool) -> Bool”

Check if all entries satisfy the predicate.

map.all(scores, (k, v) => v > 0)

map.count(m: Map[K, V], f: Fn[K, V] -> Bool) -> Int

Section titled “map.count(m: Map[K, V], f: Fn[K, V] -> Bool) -> Int”

Count entries that satisfy the predicate.

map.count(scores, (k, v) => v >= 80)

map.find(m: Map[K, V], f: Fn[K, V] -> Bool) -> Option[(K, V)]

Section titled “map.find(m: Map[K, V], f: Fn[K, V] -> Bool) -> Option[(K, V)]”

Find the first entry matching the predicate. Returns Option[(K, V)].

map.find(scores, (k, v) => v >= 90)

map.update(m: Map[K, V], key: K, f: Fn[V] -> V) -> Map[K, V]

Section titled “map.update(m: Map[K, V], key: K, f: Fn[V] -> V) -> Map[K, V]”

Update the value at a key using a function. Key must exist.

map.update(scores, "alice", (v) => v + 10)

map.insert(m: Map[K, V], key: K, value: V) -> Unit

Section titled “map.insert(m: Map[K, V], key: K, value: V) -> Unit”

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)