You are currently looking at the v6.0 - v8.2 docs (Reason v3.6 syntax edition). You can find the latest API docs here.
(These docs cover all versions between v3 to v8 and are equivalent to the old BuckleScript docs before the rebrand)
MapDict
This module seprate identity from data, it is a bit more verboe but slightly more efficient due to the fact that there is no need to pack identity and data back after each operation
Advanced usage only
t
REtype t('key, 'value, 'id);
cmp
REtype cmp('key, 'id) = Belt_Id.cmp('key, 'id);
empty
RElet empty: t('k, 'v, 'id);
isEmpty
RElet isEmpty: t('k, 'v, 'id) => bool;
has
RElet has: (t('k, 'a, 'id), 'k, ~cmp: cmp('k, 'id)) => bool;
cmpU
RElet cmpU:
(t('k, 'v, 'id), t('k, 'v, 'id), ~kcmp: cmp('k, 'id), ~vcmp: [@bs] (('v, 'v) => int)) => int;
cmp
RElet cmp: (t('k, 'v, 'id), t('k, 'v, 'id), ~kcmp: cmp('k, 'id), ~vcmp: ('v, 'v) => int) => int;
eqU
RElet eqU:
(t('k, 'a, 'id), t('k, 'a, 'id), ~kcmp: cmp('k, 'id), ~veq: [@bs] (('a, 'a) => bool)) => bool;
eq
RElet eq: (t('k, 'a, 'id), t('k, 'a, 'id), ~kcmp: cmp('k, 'id), ~veq: ('a, 'a) => bool) => bool;
eq(m1, m2, cmp)
tests whether the maps m1
and m2
are equal, that is, contain equal keys and associate them with equal data. cmp
is the equality predicate used to compare the data associated with the keys.
findFirstByU
RElet findFirstByU: (t('k, 'v, 'id), [@bs] (('k, 'v) => bool)) => option(('k, 'v));
findFirstBy
RElet findFirstBy: (t('k, 'v, 'id), ('k, 'v) => bool) => option(('k, 'v));
findFirstBy(m, p)
uses function f
to find the first key value pair to match predicate p
.
REmodule IntCmp =
Belt.Id.MakeComparable({
type t = int;
let cmp = Pervasives.compare;
});
let s0 = Belt.Map.Dict.fromArray([|(4, "4"), (1, "1"), (2, "2"), (3, "3")|], ~cmp=IntCmp.cmp);
Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4"));
forEachU
RElet forEachU: (t('k, 'a, 'id), [@bs] (('k, 'a) => unit)) => unit;
forEach
RElet forEach: (t('k, 'a, 'id), ('k, 'a) => unit) => unit;
forEach(m, f)
applies f
to all bindings in map m
. f
receives the key 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.
reduceU
RElet reduceU: (t('k, 'a, 'id), 'b, [@bs] (('b, 'k, 'a) => 'b)) => 'b;
reduce
RElet 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.
everyU
RElet everyU: (t('k, 'a, 'id), [@bs] (('k, 'a) => bool)) => bool;
every
RElet every: (t('k, 'a, 'id), ('k, 'a) => bool) => bool;
every(m, p)
checks if all the bindings of the map satisfy the predicate p
. Order unspecified
someU
RElet someU: (t('k, 'a, 'id), [@bs] (('k, 'a) => bool)) => bool;
some
RElet 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
. Order unspecified
size
RElet size: t('k, 'a, 'id) => int;
toList
RElet toList: t('k, 'a, 'id) => list(('k, 'a));
In increasing order.
toArray
RElet toArray: t('k, 'a, 'id) => array(('k, 'a));
fromArray
RElet fromArray: (array(('k, 'a)), ~cmp: cmp('k, 'id)) => t('k, 'a, 'id);
keysToArray
RElet keysToArray: t('k, 'a, 'id) => array('k);
valuesToArray
RElet valuesToArray: t('k, 'a, 'id) => array('a);
minKey
RElet minKey: t('k, 'a, 'b) => option('k);
minKeyUndefined
RElet minKeyUndefined: t('k, 'a, 'b) => Js.undefined('k);
maxKey
RElet maxKey: t('k, 'a, 'b) => option('k);
maxKeyUndefined
RElet maxKeyUndefined: t('k, 'a, 'b) => Js.undefined('k);
minimum
RElet minimum: t('k, 'a, 'b) => option(('k, 'a));
minUndefined
RElet minUndefined: t('k, 'a, 'b) => Js.undefined(('k, 'a));
maximum
RElet maximum: t('k, 'a, 'b) => option(('k, 'a));
maxUndefined
RElet maxUndefined: t('k, 'a, 'b) => Js.undefined(('k, 'a));
get
RElet get: (t('k, 'a, 'id), 'k, ~cmp: cmp('k, 'id)) => option('a);
getUndefined
RElet getUndefined: (t('k, 'a, 'id), 'k, ~cmp: cmp('k, 'id)) => Js.undefined('a);
getWithDefault
RElet getWithDefault: (t('k, 'a, 'id), 'k, 'a, ~cmp: cmp('k, 'id)) => 'a;
getExn
RElet getExn: (t('k, 'a, 'id), 'k, ~cmp: cmp('k, 'id)) => 'a;
checkInvariantInternal
RElet checkInvariantInternal: t('a, 'b, 'c) => unit;
remove
RElet remove: (t('a, 'b, 'id), 'a, ~cmp: cmp('a, 'id)) => t('a, 'b, 'id);
remove(m, x)
returns a map containing the same bindings as m
, except for x
which is unbound in the returned map.
removeMany
RElet removeMany: (t('a, 'b, 'id), array('a), ~cmp: cmp('a, 'id)) => t('a, 'b, 'id);
set
RElet set: (t('a, 'b, 'id), 'a, 'b, ~cmp: cmp('a, 'id)) => t('a, 'b, 'id);
set(m, x, y)
returns a map containing the same bindings as m
, plus a binding of x
to y
. If x
was already bound in m
, its previous binding disappears.
updateU
RElet updateU:
(t('a, 'b, 'id), 'a, [@bs] (option('b) => option('b)), ~cmp: cmp('a, 'id)) => t('a, 'b, 'id);
update
RElet update: (t('a, 'b, 'id), 'a, option('b) => option('b), ~cmp: cmp('a, 'id)) => t('a, 'b, 'id);
mergeU
RElet mergeU:
(
t('a, 'b, 'id),
t('a, 'c, 'id),
[@bs] (('a, option('b), option('c)) => option('d)),
~cmp: cmp('a, 'id)
) =>
t('a, 'd, 'id);
merge
RElet merge:
(
t('a, 'b, 'id),
t('a, 'c, 'id),
('a, option('b), option('c)) => option('d),
~cmp: cmp('a, 'id)
) =>
t('a, 'd, 'id);
merge(m1, m2, f)
computes a map whose keys is a subset of keys of m1
and of m2
. The presence of each such binding, and the corresponding value, is determined with the function f
.
mergeMany
RElet mergeMany: (t('a, 'b, 'id), array(('a, 'b)), ~cmp: cmp('a, 'id)) => t('a, 'b, 'id);
keepU
RElet keepU: (t('k, 'a, 'id), [@bs] (('k, 'a) => bool)) => t('k, 'a, 'id);
keep
RElet keep: (t('k, 'a, 'id), ('k, 'a) => bool) => t('k, 'a, 'id);
keep(m, p)
returns the map with all the bindings in m
that satisfy predicate p
.
partitionU
RElet partitionU: (t('k, 'a, 'id), [@bs] (('k, 'a) => bool)) => (t('k, 'a, 'id), t('k, 'a, 'id));
partition
RElet partition: (t('k, 'a, 'id), ('k, 'a) => bool) => (t('k, 'a, 'id), t('k, 'a, 'id));
partition(m, p)
returns a pair of maps (m1, m2)
, where m1
contains all the bindings of s
that satisfy the predicate p
, and m2
is the map with all the bindings of s
that do not satisfy p
.
split
RElet split:
(t('a, 'b, 'id), 'a, ~cmp: cmp('a, 'id)) => ((t('a, 'b, 'id), t('a, 'b, 'id)), option('b));
split(x, m)
returns a triple (l, data, r)
, where l
is the map with all the bindings of m
whose key is strictly less than x
; r
is the map with all the bindings of m
whose key is strictly greater than x
; data
is None
if m
contains no binding for x
, or Some(v)
if m
binds v
to x
.
mapU
RElet mapU: (t('k, 'a, 'id), [@bs] ('a => 'b)) => t('k, 'b, 'id);
map
RElet 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.
mapWithKeyU
RElet mapWithKeyU: (t('k, 'a, 'id), [@bs] (('k, 'a) => 'b)) => t('k, 'b, 'id);
mapWithKey
RElet mapWithKey: (t('k, 'a, 'id), ('k, 'a) => 'b) => t('k, 'b, 'id);