WeakSet
Bindings to JavaScript's WeakSet.
Weak sets store references to objects without preventing those objects from being garbage collected.
t
type t<'a>Mutable weak set storing object references of type 'a.
make
let make: unit => t<'a>Creates an empty weak set.
See WeakSet on MDN.
Examples
RESCRIPTlet visited = WeakSet.make()
WeakSet.has(visited, Object.make()) == false
add
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
RESCRIPTlet set = WeakSet.make()
let node = Object.make()
WeakSet.add(set, node)
WeakSet.has(set, node) == true
delete
let delete: (t<'a>, 'a) => booldelete(set, value) removes value and returns true if an entry existed.
See WeakSet.prototype.delete on MDN.
Examples
RESCRIPTlet set = WeakSet.make()
let node = Object.make()
let _ = WeakSet.add(set, node)
WeakSet.delete(set, node) == true
WeakSet.delete(set, node) == false
has
let has: (t<'a>, 'a) => boolhas(set, value) checks whether value exists in the weak set.
See WeakSet.prototype.has on MDN.
Examples
RESCRIPTlet set = WeakSet.make()
let node = Object.make()
WeakSet.has(set, node) == false
let _ = WeakSet.add(set, node)
WeakSet.has(set, node) == true
ignore
let ignore: t<'a> => unitignore(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.