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.
from_list
Section titled “from_list”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.
insert
Section titled “insert”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.
remove
Section titled “remove”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.
update
Section titled “update”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.
contains
Section titled “contains”fn contains[K: Ord, V](m: Map[K, V], key: K) -> BoolWhether key is in m.
fn size[K, V](m: Map[K, V]) -> IntThe number of keys.
is_empty
Section titled “is_empty”fn is_empty[K, V](m: Map[K, V]) -> BoolWhether 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.
to_list
Section titled “to_list”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.
values
Section titled “values”fn values[K, V](m: Map[K, V]) -> List[V]The values in key order.
map_values
Section titled “map_values”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.
filter
Section titled “filter”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).