Module Belt.MutableMap

Belt.MutableMap

The top level provides generic mutable map operations.

It also has two specialized inner modules Belt.MutableMap.Int and Belt.MutableMap.String

module Int: { ... };
module String: { ... };

A mutable sorted map module which allows customize compare behavior.

Same as Belt.Map, but mutable.

type t('k, 'v, 'id);
type id('key, 'id) = (module Belt__.Belt_Id.Comparable with type identity = 'id and type t = 'key);
let make: id:id('k, 'id) => t('k, 'a, 'id);
let clear: t(_, _, _) => unit;
let isEmpty: t(_, _, _) => bool;
let has: t('k, _, _) => 'k => bool;
let cmpU: t('k, 'a, 'id) => t('k, 'a, 'id) => Js.Fn.arity2(('a => 'a => int)) => int;
let cmp: t('k, 'a, 'id) => t('k, 'a, 'id) => ('a => 'a => int) => int;

cmp m1 m2 cmp First compare by size, if size is the same, compare by key, value pair

let eqU: t('k, 'a, 'id) => t('k, 'a, 'id) => Js.Fn.arity2(('a => 'a => bool)) => bool;
let eq: t('k, 'a, 'id) => t('k, 'a, 'id) => ('a => 'a => bool) => bool;

eq m1 m2 eqf tests whether the maps m1 and m2 are equal, that is, contain equal keys and associate them with equal data. eqf is the equality predicate used to compare the data associated with the keys.

let forEachU: t('k, 'a, 'id) => Js.Fn.arity2(('k => 'a => unit)) => unit;
let forEach: t('k, 'a, 'id) => ('k => 'a => unit) => unit;

forEach m f applies f to all bindings in map m. f receives the 'k as first argument, and the associated value as second argument. The bindings are passed to f in increasing order with respect to the ordering over the type of the keys.

let reduceU: t('k, 'a, 'id) => 'b => Js.Fn.arity3(('b => 'k => 'a => 'b)) => 'b;
let reduce: t('k, 'a, 'id) => 'b => ('b => 'k => 'a => 'b) => 'b;

reduce m a f computes (f kN dN ... (f k1 d1 a)...), where k1 ... kN are the keys of all bindings in m (in increasing order), and d1 ... dN are the associated data.

let everyU: t('k, 'a, 'id) => Js.Fn.arity2(('k => 'a => bool)) => bool;
let every: t('k, 'a, 'id) => ('k => 'a => bool) => bool;

every m p checks if all the bindings of the map satisfy the predicate p.

let someU: t('k, 'a, 'id) => Js.Fn.arity2(('k => 'a => bool)) => bool;
let some: t('k, 'a, 'id) => ('k => 'a => bool) => bool;

some m p checks if at least one binding of the map satisfy the predicate p.

let size: t('k, 'a, 'id) => int;
let toList: t('k, 'a, 'id) => list(('k, 'a));

In increasing order

let toArray: t('k, 'a, 'id) => array(('k, 'a));

In increasing order

let fromArray: array(('k, 'a)) => id:id('k, 'id) => t('k, 'a, 'id);
let keysToArray: t('k, _, _) => array('k);
let valuesToArray: t(_, 'a, _) => array('a);
let minKey: t('k, _, _) => option('k);
let minKeyUndefined: t('k, _, _) => Js.undefined('k);
let maxKey: t('k, _, _) => option('k);
let maxKeyUndefined: t('k, _, _) => Js.undefined('k);
let minimum: t('k, 'a, _) => option(('k, 'a));
let minUndefined: t('k, 'a, _) => Js.undefined(('k, 'a));
let maximum: t('k, 'a, _) => option(('k, 'a));
let maxUndefined: t('k, 'a, _) => Js.undefined(('k, 'a));
let get: t('k, 'a, 'id) => 'k => option('a);
let getUndefined: t('k, 'a, 'id) => 'k => Js.undefined('a);
let getWithDefault: t('k, 'a, 'id) => 'k => 'a => 'a;
let getExn: t('k, 'a, 'id) => 'k => 'a;
let checkInvariantInternal: t(_, _, _) => unit;

raise when invariant is not held

let remove: t('k, 'a, 'id) => 'k => unit;

remove m x do the in-place modification,

let removeMany: t('k, 'a, 'id) => array('k) => unit;
let set: t('k, 'a, 'id) => 'k => 'a => unit;

set m x y do the in-place modification

let updateU: t('k, 'a, 'id) => 'k => Js.Fn.arity1((option('a) => option('a))) => unit;
let update: t('k, 'a, 'id) => 'k => (option('a) => option('a)) => unit;
let mergeMany: t('k, 'a, 'id) => array(('k, 'a)) => unit;
let mapU: t('k, 'a, 'id) => Js.Fn.arity1(('a => 'b)) => t('k, 'b, 'id);
let map: t('k, 'a, 'id) => ('a => 'b) => t('k, 'b, 'id);

map m f returns a map with same domain as m, where the associated value a of all bindings of m has been replaced by the result of the application of f to a. The bindings are passed to f in increasing order with respect to the ordering over the type of the keys.

let mapWithKeyU: t('k, 'a, 'id) => Js.Fn.arity2(('k => 'a => 'b)) => t('k, 'b, 'id);
let mapWithKey: t('k, 'a, 'id) => ('k => 'a => 'b) => t('k, 'b, 'id);