ReScript HomeReScript Home
DocsPlaygroundBlogCommunityPackages
  • Playground
  • Blog
  • Community
  • Packages
  • X
  • Bluesky
  • GitHub
  • Forum
Language ManualAPISyntax LookupReact
v11v9.1 - v10.1v8.2 - v9.0v6.0 - v8.1
Overview
Belt
submodules
  • Array
  • Float
  • HashMap
    • String
    • Int
    HashSet
    • String
    • Int
    Id
    • MakeHashable
    • MakeHashableU
    • MakeComparable
    • MakeComparableU
  • Int
  • List
  • Map
    • Dict
    • String
    • Int
    MutableMap
    • String
    • Int
  • MutableQueue
  • MutableSet
    • String
    • Int
  • MutableStack
  • Option
  • Range
  • Result
  • Set
    • Dict
    • String
    • Int
    SortArray
    • String
    • Int
    Docs / API / Dict

    Dict

    This module separates identity from data, it is a bit more verbose 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

    checkInvariantInternal

    RESCRIPT
    let checkInvariantInternal: t<'a, 'b, 'c> => unit

    cmp

    RESCRIPT
    type cmp<'key, 'id> = Belt_Id.cmp<'key, 'id>

    cmp

    RESCRIPT
    let cmp: ( t<'k, 'v, 'id>, t<'k, 'v, 'id>, ~kcmp: cmp<'k, 'id>, ~vcmp: ('v, 'v) => int, ) => int

    cmpU

    Deprecated

    Use cmp instead

    RESCRIPT
    let cmpU: ( t<'k, 'v, 'id>, t<'k, 'v, 'id>, ~kcmp: cmp<'k, 'id>, ~vcmp: ('v, 'v) => int, ) => int

    empty

    RESCRIPT
    let empty: t<'k, 'v, 'id>

    eq

    RESCRIPT
    let 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.

    eqU

    Deprecated

    Use eq instead

    RESCRIPT
    let eqU: ( t<'k, 'a, 'id>, t<'k, 'a, 'id>, ~kcmp: cmp<'k, 'id>, ~veq: ('a, 'a) => bool, ) => bool

    every

    RESCRIPT
    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. Order unspecified

    everyU

    Deprecated

    Use every instead

    RESCRIPT
    let everyU: (t<'k, 'a, 'id>, ('k, 'a) => bool) => bool

    findFirstBy

    RESCRIPT
    let 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.

    Examples

    RESCRIPT
    module 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"))

    findFirstByU

    Deprecated

    Use findFirstBy instead

    RESCRIPT
    let findFirstByU: (t<'k, 'v, 'id>, ('k, 'v) => bool) => option<('k, 'v)>

    forEach

    RESCRIPT
    let 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.

    forEachU

    Deprecated

    Use forEach instead

    RESCRIPT
    let forEachU: (t<'k, 'a, 'id>, ('k, 'a) => unit) => unit

    fromArray

    RESCRIPT
    let fromArray: (array<('k, 'a)>, ~cmp: cmp<'k, 'id>) => t<'k, 'a, 'id>

    get

    RESCRIPT
    let get: (t<'k, 'a, 'id>, 'k, ~cmp: cmp<'k, 'id>) => option<'a>

    getExn

    RESCRIPT
    let getExn: (t<'k, 'a, 'id>, 'k, ~cmp: cmp<'k, 'id>) => 'a

    getOrThrow

    RESCRIPT
    let getOrThrow: (t<'k, 'a, 'id>, 'k, ~cmp: cmp<'k, 'id>) => 'a

    getUndefined

    RESCRIPT
    let getUndefined: (t<'k, 'a, 'id>, 'k, ~cmp: cmp<'k, 'id>) => Js.undefined<'a>

    getWithDefault

    RESCRIPT
    let getWithDefault: (t<'k, 'a, 'id>, 'k, 'a, ~cmp: cmp<'k, 'id>) => 'a

    has

    RESCRIPT
    let has: (t<'k, 'a, 'id>, 'k, ~cmp: cmp<'k, 'id>) => bool

    isEmpty

    RESCRIPT
    let isEmpty: t<'k, 'v, 'id> => bool

    keep

    RESCRIPT
    let 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.

    keepU

    Deprecated

    Use keep instead

    RESCRIPT
    let keepU: (t<'k, 'a, 'id>, ('k, 'a) => bool) => t<'k, 'a, 'id>

    keysToArray

    RESCRIPT
    let keysToArray: t<'k, 'a, 'id> => array<'k>

    map

    RESCRIPT
    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.

    mapU

    Deprecated

    Use map instead

    RESCRIPT
    let mapU: (t<'k, 'a, 'id>, 'a => 'b) => t<'k, 'b, 'id>

    mapWithKey

    RESCRIPT
    let mapWithKey: (t<'k, 'a, 'id>, ('k, 'a) => 'b) => t<'k, 'b, 'id>

    mapWithKeyU

    Deprecated

    Use mapWithKey instead

    RESCRIPT
    let mapWithKeyU: (t<'k, 'a, 'id>, ('k, 'a) => 'b) => t<'k, 'b, 'id>

    maximum

    RESCRIPT
    let maximum: t<'k, 'a, 'b> => option<('k, 'a)>

    maxKey

    RESCRIPT
    let maxKey: t<'k, 'a, 'b> => option<'k>

    maxKeyUndefined

    RESCRIPT
    let maxKeyUndefined: t<'k, 'a, 'b> => Js.undefined<'k>

    maxUndefined

    RESCRIPT
    let maxUndefined: t<'k, 'a, 'b> => Js.undefined<('k, 'a)>

    merge

    RESCRIPT
    let 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

    RESCRIPT
    let mergeMany: ( t<'a, 'b, 'id>, array<('a, 'b)>, ~cmp: cmp<'a, 'id>, ) => t<'a, 'b, 'id>

    mergeU

    Deprecated

    Use merge instead

    RESCRIPT
    let mergeU: ( t<'a, 'b, 'id>, t<'a, 'c, 'id>, ('a, option<'b>, option<'c>) => option<'d>, ~cmp: cmp<'a, 'id>, ) => t<'a, 'd, 'id>

    minimum

    RESCRIPT
    let minimum: t<'k, 'a, 'b> => option<('k, 'a)>

    minKey

    RESCRIPT
    let minKey: t<'k, 'a, 'b> => option<'k>

    minKeyUndefined

    RESCRIPT
    let minKeyUndefined: t<'k, 'a, 'b> => Js.undefined<'k>

    minUndefined

    RESCRIPT
    let minUndefined: t<'k, 'a, 'b> => Js.undefined<('k, 'a)>

    partition

    RESCRIPT
    let 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.

    partitionU

    Deprecated

    Use partition instead

    RESCRIPT
    let partitionU: ( t<'k, 'a, 'id>, ('k, 'a) => bool, ) => (t<'k, 'a, 'id>, t<'k, 'a, 'id>)

    reduce

    RESCRIPT
    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.

    reduceU

    Deprecated

    Use reduce instead

    RESCRIPT
    let reduceU: (t<'k, 'a, 'id>, 'b, ('b, 'k, 'a) => 'b) => 'b

    remove

    RESCRIPT
    let 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

    RESCRIPT
    let removeMany: ( t<'a, 'b, 'id>, array<'a>, ~cmp: cmp<'a, 'id>, ) => t<'a, 'b, 'id>

    set

    RESCRIPT
    let 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.

    size

    RESCRIPT
    let size: t<'k, 'a, 'id> => int

    some

    RESCRIPT
    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. Order unspecified

    someU

    Deprecated

    Use some instead

    RESCRIPT
    let someU: (t<'k, 'a, 'id>, ('k, 'a) => bool) => bool

    split

    RESCRIPT
    let 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.

    t

    RESCRIPT
    type t<'key, 'value, 'id>

    toArray

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

    toList

    RESCRIPT
    let toList: t<'k, 'a, 'id> => list<('k, 'a)>

    In increasing order.

    update

    RESCRIPT
    let update: ( t<'a, 'b, 'id>, 'a, option<'b> => option<'b>, ~cmp: cmp<'a, 'id>, ) => t<'a, 'b, 'id>

    updateU

    Deprecated

    Use update instead

    RESCRIPT
    let updateU: ( t<'a, 'b, 'id>, 'a, option<'b> => option<'b>, ~cmp: cmp<'a, 'id>, ) => t<'a, 'b, 'id>

    valuesToArray

    RESCRIPT
    let valuesToArray: t<'k, 'a, 'id> => array<'a>
    Types and values
    • v
      checkInvariantInternal
    • t
      cmp
    • v
      cmp
    • v
      cmpU
      D
    • v
      empty
    • v
      eq
    • v
      eqU
      D
    • v
      every
    • v
      everyU
      D
    • v
      findFirstBy
    • v
      findFirstByU
      D
    • v
      forEach
    • v
      forEachU
      D
    • v
      fromArray
    • v
      get
    • v
      getExn
    • v
      getOrThrow
    • v
      getUndefined
    • v
      getWithDefault
    • v
      has
    • v
      isEmpty
    • v
      keep
    • v
      keepU
      D
    • v
      keysToArray
    • v
      map
    • v
      mapU
      D
    • v
      mapWithKey
    • v
      mapWithKeyU
      D
    • v
      maximum
    • v
      maxKey
    • v
      maxKeyUndefined
    • v
      maxUndefined
    • v
      merge
    • v
      mergeMany
    • v
      mergeU
      D
    • v
      minimum
    • v
      minKey
    • v
      minKeyUndefined
    • v
      minUndefined
    • v
      partition
    • v
      partitionU
      D
    • v
      reduce
    • v
      reduceU
      D
    • v
      remove
    • v
      removeMany
    • v
      set
    • v
      size
    • v
      some
    • v
      someU
      D
    • v
      split
    • t
      t
    • v
      toArray
    • v
      toList
    • v
      update
    • v
      updateU
      D
    • v
      valuesToArray

    © 2026 The ReScript Project

    About
    • Community
    • ReScript Association
    Find us on