WeakSet

Bindings to JavaScript's WeakSet.

Weak sets store references to objects without preventing those objects from being garbage collected.

add

RESCRIPT
let add: (t<'a>, 'a) => t<'a>

add(set, value) inserts value into the weak set and returns the set for chaining.

See WeakSet.prototype.add on MDN.

Examples

RESCRIPT
let set = WeakSet.make() let node = Object.make() WeakSet.add(set, node) WeakSet.has(set, node) == true

delete

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

delete(set, value) removes value and returns true if an entry existed.

See WeakSet.prototype.delete on MDN.

Examples

RESCRIPT
let set = WeakSet.make() let node = Object.make() let _ = WeakSet.add(set, node) WeakSet.delete(set, node) == true WeakSet.delete(set, node) == false

has

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

has(set, value) checks whether value exists in the weak set.

See WeakSet.prototype.has on MDN.

Examples

RESCRIPT
let set = WeakSet.make() let node = Object.make() WeakSet.has(set, node) == false let _ = WeakSet.add(set, node) WeakSet.has(set, node) == true

ignore

RESCRIPT
let ignore: t<'a> => unit

ignore(weakSet) ignores the provided weakSet 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.

make

RESCRIPT
let make: unit => t<'a>

Creates an empty weak set.

See WeakSet on MDN.

Examples

RESCRIPT
let visited = WeakSet.make() WeakSet.has(visited, Object.make()) == false

t

RESCRIPT
type t<'a>

Mutable weak set storing object references of type 'a.