Skip to main content
Version: Next

map

Maps from keys to values, where the bindings key/value are ordered by increasing keys.

type t<key, value> = map<key, value>

The type Map.t<key, value> is an alias for map<key,value>.

empty: <key, value>t<key, value>

The value Map.empty is the empty map. In some contexts, it is useful to annotate it with its type, for example: (Map.empty as map<int, string>).

get_and_update: <key, value>(key: key, upd: option<value>, map: t<key, value>) => [option<value>, t<key, value>]

The call Map.get_and_update(key, ["None" as "None"], map) returns a copy of the map map without the entry for the key key in map (no change if the key is absent). The call Map.get_and_update(key, ["Some" as "Some", value], map) returns a copy of the map map where there is an entry for the key key associated with the value value. In both cases, if there was already a value v bound to key, it is returned as ["Some" as "Some", v], otherwise ["None" as "None"].

update: <key, value>(key: key, upd: option<value>, map: t<key, value>) => t<key, value>

The call Map.update(key, ["None" as "None"], map) returns a copy of the map map without the entry for the key key in map (no change if the key is absent). The call Map.update(key, ["Some" as "Some", value], map) returns the map map where there is an entry for the key key associated with the value value. In both cases, the value originally bound to key is lost. See Map.get_and_update.

add: <key, value>(key: key, value: value, map: t<key, value>) => t<key, value>

The call Map.add(key, value, map) returns a copy of the map where there is a binding of key key to value value. If there is a binding for key in map, then it is lost.

remove: <key, value>(key: key, map: t<key, value>) => t<key, value>

The call Map.remove(key, map) returns a copy of the map map where the binding for key key is absent.

literal: <key, value>(bindings: list<[key, value]>) => t<key, value>

The call Map.literal(list([[k1,v1], ..., [kn,vn]])) returns a map from the pairs of key/value in the list. Note: The list must be a literal, not an expression (compile-time list of values).

of_list: <key, value>(bindings: list<[key, value]>) => t<key, value>

The call Map.of_list(bindings) returns a map from the pairs of key/value in the list bindings. Note: Use Map.literal instead if using a literal list.

size: <key, value>(map: t<key, value>) => nat

The call Map.size(map) evaluates in the number of entries in the map map.

mem: <key, value>(key: key, map: t<key, value>) => bool

The call Map.mem(key, map) is true if, and only if, the key key is in the map map.

find_opt: <key, value>(key: key, map: t<key, value>) => option<value>

The call Map.find_opt(key, map) returns ["None" as "None"] if the key key is present in the map map; otherwise, it is ["Some" as "Some", v], where v is the value associated to key in map.

find: <key, value>(key: key, map: t<key, value>) => value

The call Map.find(key, map) returns the value associated to key in map. If the key is absent, the execution fails with the string "MAP FIND".

fold: <key, value, acc>(f: (_: [acc, [key, value]]) => acc, map: t<key, value>, acc: acc) => acc

The call Map.fold(f, map, init) is f (... f (f (init, [k1,v1]), [k2,v2]), ..., [kn,vn]) where [k1,v1], [k2,v2], ..., [kn,vn] are the bindings in the map map, in increasing order of the keys k1, k2, ..., and kn.

iter: <key, value>(f: (_: [key, value]) => unit, map: t<key, value>) => unit

The call Map.iter(f, map) is {f (k1,v1); (k2,v2); ...; f (kn,vn);}.

map: <key, value, new_value>(f: (_: [key, value]) => new_value, map: t<key, value>) => t<key, new_value>

The call Map.map(f, m), where the map m contains the bindings [k1,v1], [k2,v2], ..., and [kn,vn] in increasing order of the keys, is the map containing the bindings [k1, f (k1,v1)], [k2, f (k2,v2)], ..., [kn, f (kn,vn)].