Module Relude_Map

type t('key, 'value, 'id) = Belt.Map.t('key'value'id);
let make: Belt.Id.comparable('key'id) => t('key'value'id);

Construct a new, empty map.

let set: 'key => 'value => t('key'value'id) => t('key'value'id);

Set the value to the provided value at the given key in the map. This will add a new key if the map doesn't currently have the provided key, or it will replace the value if the key exists.

As with other operations that "change" a map, the original map is not mutated; instead a new immutable copy is returned.

let singleton: Belt.Id.comparable('key'id) => 'key => 'value => t('key'value'id);

Contruct a new map from the provided key and value.

let isEmpty: t('key'value'id) => bool;

Determine whether a map is empty.

let contains: 'key => t('key'value'id) => bool;

Determine whether a map contains a given key.

let compareInt: ('value => 'value => int) => t('key'value'id) => t('key'value'id) => int;

Compare the ordering of two maps, given a comparator function capable of comparing each value in the map. compareInt expects the provided function to return an int representing the comparison, and compareInt intself will return an int.

let compareBy: ('value => 'value => BsBastet.Interface.ordering) => t('key'value'id) => t('key'value'id) => BsBastet.Interface.ordering;

Compare the ordering of two maps, given a comparator function capable of comparing each value in the map. compare expects the provided function to return an ordering representing the comparison, and compare itself will return an ordering value.

let eqBy: ('value => 'value => bool) => t('key'value'id) => t('key'value'id) => bool;

Given an equality function capable of testing values for equality, determine whether two maps are equal by checking whether they have equal keys, and equal values at each key.

let find: ('key => 'value => bool) => t('key'value'id) => option(('key, 'value));

Find (optionally) the first key/value pair in a map matching the provided predicate function.

let forEach: ('key => 'value => unit) => t('key'value'id) => unit;

Iterate over each key/value pair in the map, calling the provided function that probably performs some side effect and returns unit. Prefer map or foldLeft in most cases.

let foldLeft: ('acc => 'key => 'value => 'acc) => 'acc => t('key'value'id) => 'acc;

Accumulate a map of key/value pairs into a single value.

let all: ('key => 'value => bool) => t('key'value'id) => bool;

Given a predicate function to be called with key/value pairs, determine whether every pair in the map satisfies the predicate. This will always return true for empty maps.

let any: ('key => 'value => bool) => t('key'value'id) => bool;

Given a predicate function to be called with key/value pairs, determine whether at least one pair in the map satisfies the predicate. This will always return false for empty maps.

let length: t('key'value'id) => int;

The count of keys in the map.

let toArray: t('key'value'id) => array(('key, 'value));

Convert a map to an array of key/value pairs. Note that the resulting array will be sorted by the ordering of the key type, not necessarily the order in which values were added to the map.

let fromArray: Belt.Id.comparable('key'id) => array(('key, 'value)) => t('key'value'id);

Convert an associated array (an array of (key, value) tuples) into a map.

let fromValueArray: Belt.Id.comparable('key'id) => ('value => 'key) => array('value) => t('key'value'id);

Convert an array of values into a map, using the provided function from value to key. This is useful when your value type can already be uniquely identified (and that identifier can be ordered).

let toList: t('key'value'id) => list(('key, 'value));

Convert a map to an associated list (a list of key/value tuples). Note that the resulting list will be sorted according to the ordering of the key type, not necessarily in the order in which values were added to the map.

let fromList: Belt.Id.comparable('key'id) => list(('key, 'value)) => t('key'value'id);

Convert an associated list (a list of (key, value) tuples) into a map.

let fromValueList: Belt.Id.comparable('key'id) => ('value => 'key) => list('value) => t('key'value'id);

Convert a list of values into a map, using the provided function from value to key. This is useful when your value type can already be uniquely identified (and that identifier can be ordered).

let keyArray: t('key'value'id) => array('key);

Return a sorted array containing each key in the map.

let keys: t('key'value'id) => list('key);

Return a sorted list containing each key in the map

let valueArray: t('key'value'id) => array('value);

Return an array of each value (sorted by key) in the map.

let values: t('key'value'id) => list('value);

Return a list of each value (sorted by key) in the map.

let minKey: t('key'value'id) => option('key);

Optionally find the smallest key, using the key ordering.

let maxKey: t('key'value'id) => option('key);

Optionally find the largest key, using the key ordering.

let min: t('key'value'id) => option(('key, 'value));

Optionally find the smallest key/value pair, using the key ordering.

let max: t('key'value'id) => option(('key, 'value));

Optionally find the largest key/value pair, using the key ordering.

let get: 'key => t('key'value'id) => option('value);

Attempt to find a value in a map, given a key.

let getOrElse: 'key => 'value => t('key'value'id) => 'value;

Attempt to find a value in a map, given a key. Use the provided fallback value if the key is not in the map.

let remove: 'key => t('key'value'id) => t('key'value'id);

Return a new copy of a map, with the provided key removed. Like other map functions that "change" a value, this returns an immutable copy. The original map is unchanged.

let removeMany: array('key) => t('key'value'id) => t('key'value'id);

Given a list of keys, remove each from the map, returning a new copy.

let update: 'key => (option('value) => option('value)) => t('key'value'id) => t('key'value'id);

At the given key, set or remove the value using the provided update function. The function will be called with the current value, if any. It may return Some(newValue) which will perform a set, or it can return None, which will perform a remove.

let merge: ('key => option('value) => option('value) => option('value)) => t('key'value'id) => t('key'value'id) => t('key'value'id);

Combine two existing maps using the provided merge function. The merge function will be called with the key being merged as well as the two possible values from the existing maps. The provided merge function should return None to remove a key, or Some(newValue) to keep the key.

The value types of the two original maps don't need to be the same, nor does the value type returned by the provided merge function.

let mergeMany: array(('key, 'value)) => t('key'value'id) => t('key'value'id);

Given an array of key/value pairs and an existin map, add each key and value in the array to the map.

TODO: it's not clear from the Belt docs what happens in the case of key conflicts.

let filter: ('key => 'value => bool) => t('key'value'id) => t('key'value'id);

Remove each key/value pair that doesn't pass the given predicate function.

let keep: ('key => 'value => bool) => t('key'value'id) => t('key'value'id);

Alias of filter

let filterNot: ('key => 'value => bool) => t('key'value'id) => t('key'value'id);

Remove each key/value pair that passes the given predicate function

let reject: ('key => 'value => bool) => t('key'value'id) => t('key'value'id);

Alias of filterNot

let partition: ('key => 'value => bool) => t('key'value'id) => (t('key'value'id), t('key'value'id));
let map: ('v1 => 'v2) => t('key'v1'id) => t('key'v2'id);

Transform each value in the map to a new value using the provided function.

let mapWithKey: ('key => 'v1 => 'v2) => t('key'v1'id) => t('key'v2'id);
let groupListBy: Belt.Id.comparable('key'id) => ('value => 'key) => list('value) => t('key, list('value), 'id);
let groupArrayBy: Belt.Id.comparable('key'id) => ('value => 'key) => array('value) => t('key, array('value), 'id);
module type MAP = { ... };
module WithOrd: (M: BsBastet.Interface.ORD) => MAP with type key = M.t;