Skip to content

@maps

Import this module with import @maps.

Function Signature Description
is_empty (m map[K:V]) -> bool Check if map is empty
contains_key (m map[K:V], key K) -> bool Check if key exists
contains_value (m map[K:V], value V) -> bool Check if any entry has the given value
get_keys (m map[K:V]) -> [K] Get all keys as an array
get_values (m map[K:V]) -> [V] Get all values as an array
get_or_default (m map[K:V], key K, default V) -> V Get value or return default if key missing
get_or_insert (&m map[K:V], key K, default V) -> V Get the value, or store default under key and return it if the key is missing
sorted_keys (m map[K:V]) -> [K] New array of the keys in ascending order; K must be string, an integer type, or char; strings order byte-wise, matching strings.compare
get_and_remove (&m map[K:V], key K) -> (V, bool) Remove key and return (value, true); if absent the map is unchanged and the result is the zero value of V with false
find_key (m map[K:V], value V) -> (K, bool) Key of the first entry in insertion order whose value equals value, with true; otherwise the zero value of K with false; V must be a primitive or string
remove_key (&m map[K:V], key K) Remove key-value pair; does nothing if key absent
clear (&m map[K:V]) Remove all entries
merge (m1 map[K:V], m2 map[K:V]) -> map[K:V] Combine two maps (m2 overwrites on conflict)
is_equal (a map[K:V], b map[K:V]) -> bool Structural equality. Compares counts, then iterates the first map’s entries in insertion order looking each key up in the second. K and V must each be a primitive (i64, u64, f64, bool, char, u8, sized variants) or string; maps with nested-composite values are rejected at compile time.

The == and != operators on maps are not allowed; use maps.is_equal(a, b) for equality. Maps have no defined ordering, so < / <= / > / >= on maps is also rejected.

Use len(m) to get the number of entries (builtin, no import needed).