prelude.Map

Part of prelude.

struct Map

A hash map from K to V.

PERSISTENT: Map.insert returns a new map and leaves the original alone, so a map can be shared without copying defensively. Keys need Eq.

let Map.new (): Map[K, V]

An empty map.

let Map.insert (m: Map[K, V]) (k: K) (v: V): Map[K, V]

A NEW map with k set to v, replacing any previous value. The original is unchanged.

let Map.get (m: Map[K, V]) (k: K): Option[V]

The value for k, or None.

let Map.contains (m: Map[K, V]) (k: K): Bool

Whether k has a value.

let Map.remove (m: Map[K, V]) (k: K): Map[K, V]

A new map without k. Removing an absent key is not an error.

let Map.len (m: Map[K, V]): Int

How many entries.

let Map.keys (m: Map[K, V]): Array[K]

Every key, in no particular order — buckets, not insertion order.

let Map.values (m: Map[K, V]): Array[V]

Every value, in the same order as Map.keys.

let Map.from_arrays (keys: Array[K]) (values: Array[V]): Map[K, V]

A map from parallel arrays, stopping at the shorter. A repeated key keeps the LAST value.