Symbol
A built-in object that serves as a namespace for globally-unique identifiers.
Compiles to a regular JavaScript Symbol.
t
type t
Type representing a Symbol.
make
let make: string => t
make(key)
Makes a new unique Symbol value.
Examples
RESCRIPTSymbol.make("sym1")->Symbol.description == Some("sym1")
getFor
let getFor: string => option<t>
getFor(key)
Searches for existing registered Symbols in the global Symbol registry with the given key and returns it if found. Otherwise a new Symbol gets created and registered with key.
Examples
RESCRIPTSymbol.getFor("sym1") == Symbol.getFor("sym1")
keyFor
let keyFor: t => option<string>
keyFor(key)
Retrieves a shared Symbol key from the global Symbol registry for the given Symbol.
Examples
RESCRIPTlet globalSym = Symbol.getFor("sym1") // Global symbol
globalSym->Option.flatMap(Symbol.description) == Some("sym1")
description
let description: t => option<string>
description
Returns Some(string)
containing the description of this symbol, or None
if the symbol has no description.
Examples
RESCRIPTlet sym = Symbol.make("sym1")
Symbol.description(sym) == Some("sym1")
toString
let toString: t => string
toString
// Returns a string representing this symbol value.
Examples
RESCRIPTlet sym = Symbol.make("sym1")
Symbol.toString(sym) == "Symbol(sym1)"
asyncIterator
let asyncIterator: t
hasInstance
let hasInstance: t
isConcatSpreadable
let isConcatSpreadable: t
iterator
let iterator: t
match
let match: t
matchAll
let matchAll: t
replace
let replace: t
search
let search: t
species
let species: t
split
let split: t
toPrimitive
let toPrimitive: t
toStringTag
let toStringTag: t
unscopables
let unscopables: t
ignore
let ignore: t => unit
ignore(symbol)
ignores the provided symbol 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.