Skip to content

Std.Map

opaque enum Map[K, V]

A map from keys of type K to values of type V, ordered by the keys.

fn empty[K, V]() -> Map[K, V]

The empty map.

fn from_list[K: Ord, V](pairs: List[(K, V)]) -> Map[K, V]

The map of the pairs. A key given twice takes its later value.

fn insert[K: Ord, V](m: Map[K, V], key: K, value: V) -> Map[K, V]

m with key mapped to value, replacing its value if it is there.

fn remove[K: Ord, V](m: Map[K, V], key: K) -> Map[K, V]

m without key. The same map if key is not there.

fn update[K: Ord, V](m: Map[K, V], key: K, f: fn(Option[V]) -> Option[V] fails E(f) uses { R(f) }) -> Map[K, V] fails E(f) uses { R(f) }

f gets the value of key (None if it is not there). Some sets the value, and None removes the key. f is called once.

fn get[K: Ord, V](m: Map[K, V], key: K) -> Option[V]

The value of key.

fn contains[K: Ord, V](m: Map[K, V], key: K) -> Bool

Whether key is in m.

fn size[K, V](m: Map[K, V]) -> Int

The number of keys.

fn is_empty[K, V](m: Map[K, V]) -> Bool

Whether the map is empty.

fn fold[K, V, B](m: Map[K, V], from: B, f: fn(B, K, V) -> B fails E(f) uses { R(f) }) -> B fails E(f) uses { R(f) }

Folds the pairs in key order, starting from from.

fn each[K, V](m: Map[K, V], f: fn(K, V) -> () fails E(f) uses { R(f) }) -> () fails E(f) uses { R(f) }

Calls f on each pair in key order. Stops at the first failure.

fn to_list[K, V](m: Map[K, V]) -> List[(K, V)]

The pairs in key order.

fn keys[K, V](m: Map[K, V]) -> List[K]

The keys in order.

fn values[K, V](m: Map[K, V]) -> List[V]

The values in key order.

fn map_values[K, V, W](m: Map[K, V], f: fn(V) -> W fails E(f) uses { R(f) }) -> Map[K, W] fails E(f) uses { R(f) }

f on each value. The keys stay. f is called in key order ([lib.api-rules]), so the left subtree is built before the value of the node, and the right one after it.

fn filter[K, V](m: Map[K, V], f: fn(K, V) -> Bool fails E(f) uses { R(f) }) -> Map[K, V] fails E(f) uses { R(f) }

The pairs for which f is True.

fn union[K: Ord, V](a: Map[K, V], b: Map[K, V]) -> Map[K, V]

The keys of both. A key in both takes its value in a (as in Haskell’s Data.Map.union).