Module Relude_HMap.WithKeyMetaUnit

We include a default HMap implementation which uses unit as it's key meta type. Note that this default map type will not work in a type-safe way for functions that iterate over the map with keyValue functions, like fold, all, any, etc.

In order to use the iterating functions, use a custom HMap with the key metadata functions needed to convert the existential 'a into a useful value.

type keyImpl('a);

An abstract type for map keys

module Key: { ... };

Key-related types and operations for an HMap

type t;

The abstract type of the HMap

let empty: t;

An empty HMap

let isEmpty: t => bool;

Indicates if the HMap is empty

let hasKey: keyImpl('a) => t => bool;

Indicates if the HMap has a value for the given key

let add: keyImpl('a) => 'a => t => t;

Adds the given key/value pair to the HMap

let singleton: keyImpl('a) => 'a => t;

Creates an HMap with the given key/value pair

let remove: keyImpl('a) => t => t;

Creates a new HMap that does not contain a value for the given key

let find: keyImpl('a) => t => option('a);

Looks up a value in the HMap for the given key

type keyValue =
| KeyValue(keyImpl('a), 'a) : keyValue
;

The type of a key/value pair in the HMap. The key captures the type of the corresponding value.

let forEach: (keyValue => unit) => t => unit;

Runs a side effect for each key/value pair in the HMap. Note: the KEY_META must provide appropriate functions for converting the existentially typed values into values of a known type.

let fold: (keyValue => 'a => 'a) => 'a => t => 'a;

Folds the HMap into a value. Note the KEY_META must provide appropriate functions for manipulating the values stored for each key.

let all: (keyValue => bool) => t => bool;

Indicates if all key/value pairs in the HMap satisfy the given predicate.

Note the KEY_META must provide appropriate functions for manipulating the values stored for each key.

let any: (keyValue => bool) => t => bool;

Indicates if any key/value pairs in the HMap satisfy the given predicate.

Note the KEY_META must provide appropriate functions for manipulating the values stored for each key.

let filter: (keyValue => bool) => t => t;

Creates a new HMap that only contains the key/value pairs that satisfy the given predicate.

Note the KEY_META must provide appropriate functions for manipulating the values stored for each key.

let size: t => int;

Gets the number of key/value pairs stored in this HMap.