map
The map module is auto-imported — no import statement needed.
Functions
Section titled “Functions”| Function | Signature | Description |
|---|---|---|
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) -> V | Get 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) -> Bool | Check 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]) -> Int | Get 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]) -> Bool | Check 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) -> A | Accumulate over all entries with an initial value. |
any | (Map[K, V], Fn[K, V] -> Bool) -> Bool | Check if any entry satisfies the predicate. |
all | (Map[K, V], Fn[K, V] -> Bool) -> Bool | Check if all entries satisfy the predicate. |
count | (Map[K, V], Fn[K, V] -> Bool) -> Int | Count 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) -> Unit | Insert a key-value pair in place. Requires var binding. |
delete | (Map[K, V], K) -> Unit | Remove a key in place. Requires var binding. |
clear | (Map[K, V]) -> Unit | Remove all entries in place. Requires var binding. |
Reference
Section titled “Reference”map.new() -> Map[K, V]
Section titled “map.new() -> Map[K, V]”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")map.keys(m: Map[K, V]) -> List[K]
Section titled “map.keys(m: Map[K, V]) -> List[K]”Get all keys as a sorted list.
map.keys(m)map.values(m: Map[K, V]) -> List[V]
Section titled “map.values(m: Map[K, V]) -> List[V]”Get all values as a list.
map.values(m)map.len(m: Map[K, V]) -> Int
Section titled “map.len(m: Map[K, V]) -> Int”Get the number of key-value pairs in the map.
map.len(m)map.entries(m: Map[K, V]) -> List[(K, V)]
Section titled “map.entries(m: Map[K, V]) -> List[(K, V)]”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)map.is_empty(m: Map[K, V]) -> Bool
Section titled “map.is_empty(m: Map[K, V]) -> Bool”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")map.delete(m: Map[K, V], key: K) -> Unit
Section titled “map.delete(m: Map[K, V], key: K) -> Unit”Remove a key in place. Requires var binding.
map.delete(m, "temp")map.clear(m: Map[K, V]) -> Unit
Section titled “map.clear(m: Map[K, V]) -> Unit”Remove all entries in place. Requires var binding.
map.clear(m)