DocsPlaygroundBlogCommunityPackages
  • Playground
  • Blog
  • Community
  • Packages
  • X
  • Bluesky
  • GitHub
  • Forum
Language ManualAPISyntax LookupReact
Overview
Stdlib
submodules
  • Array
  • ArrayBuffer
  • AsyncIterator
  • BigInt
  • BigInt64Array
    • Constants
    BigUint64Array
    • Constants
  • Bool
  • Console
  • DataView
  • Date
    • UTC
  • Dict
  • Error
    • URIError
    • TypeError
    • SyntaxError
    • ReferenceError
    • RangeError
    • EvalError
  • Exn
  • Float
    • Constants
    Float32Array
    • Constants
    Float64Array
    • Constants
    Int
    • Ref
    • Bitwise
    • Constants
    Int16Array
    • Constants
    Int32Array
    • Constants
    Int8Array
    • Constants
  • IntervalId
  • Intl
    • Segments
    • Segmenter
    • RelativeTimeFormat
    • PluralRules
    • NumberFormat
      • Grouping
    • Locale
    • ListFormat
    • DateTimeFormat
    • Collator
    • Common
  • Iterator
  • JSON
    • Decode
    • Encode
    • Classify
    JsError
    • URIError
    • TypeError
    • SyntaxError
    • ReferenceError
    • RangeError
    • EvalError
  • JsExn
  • Lazy
  • List
  • Map
  • Math
    • Int
    • Constants
  • Null
  • Nullable
  • Object
  • Option
  • Ordering
  • Pair
  • Promise
  • RegExp
    • Result
  • Result
  • Set
  • String
  • Symbol
  • TimeoutId
  • Type
    • Classify
  • TypedArray
  • Uint16Array
    • Constants
    Uint32Array
    • Constants
    Uint8Array
    • Constants
    Uint8ClampedArray
    • Constants
  • WeakMap
    • t
      t
    • v
      make
    • v
      get
    • v
      has
    • v
      set
    • v
      delete
    • v
      ignore
  • WeakSet
  • Docs / API / Stdlib / Weakmap

    WeakMap

    Bindings to JavaScript's WeakMap.

    Weak maps keep key/value pairs where keys must be objects and the references do not prevent garbage collection.

    t

    RESCRIPT
    type t<'k, 'v>

    Mutable weak map storing values of type 'v with object keys 'k.

    make

    RESCRIPT
    let make: unit => t<'k, 'v>

    Creates an empty weak map.

    See WeakMap on MDN.

    Examples

    RESCRIPT
    let cache = WeakMap.make() WeakMap.get(cache, Object.make()) == None

    get

    RESCRIPT
    let get: (t<'k, 'v>, 'k) => option<'v>

    get(map, key) returns Some(value) when key exists, otherwise None.

    See WeakMap.prototype.get on MDN.

    Examples

    RESCRIPT
    let cache = WeakMap.make() let key = Object.make() WeakMap.get(cache, key) == None let _ = WeakMap.set(cache, key, "user") WeakMap.get(cache, key) == Some("user")

    has

    RESCRIPT
    let has: (t<'k, 'v>, 'k) => bool

    has(map, key) checks whether key exists in the weak map.

    See WeakMap.prototype.has on MDN.

    Examples

    RESCRIPT
    let cache = WeakMap.make() let key = Object.make() WeakMap.has(cache, key) == false let _ = WeakMap.set(cache, key, ()) WeakMap.has(cache, key) == true

    set

    RESCRIPT
    let set: (t<'k, 'v>, 'k, 'v) => t<'k, 'v>

    set(map, key, value) stores value for key and returns the map for chaining.

    See WeakMap.prototype.set on MDN.

    Examples

    RESCRIPT
    let cache = WeakMap.make() let key = Object.make() let _ = WeakMap.set(cache, key, 42) WeakMap.get(cache, key) == Some(42)

    delete

    RESCRIPT
    let delete: (t<'k, 'v>, 'k) => bool

    delete(map, key) removes key and returns true if an entry existed.

    See WeakMap.prototype.delete on MDN.

    Examples

    RESCRIPT
    let cache = WeakMap.make() let key = Object.make() WeakMap.delete(cache, key) == false let _ = WeakMap.set(cache, key, 1) WeakMap.delete(cache, key) == true

    ignore

    RESCRIPT
    let ignore: t<'k, 'v> => unit

    ignore(weakMap) ignores the provided weakMap and returns unit.

    This helper is useful when you want to discard a value (for example, the result of an operation with side effects) without having to store or process it further.

    Types and values
    • t
      t
    • v
      make
    • v
      get
    • v
      has
    • v
      set
    • v
      delete
    • v
      ignore

    © 2025 The ReScript Project

    About
    • Community
    • ReScript Association
    Find us on