Symbol

A built-in object that serves as a namespace for globally-unique identifiers.

Compiles to a regular JavaScript Symbol.

asyncIterator

RESCRIPT
let asyncIterator: t

asyncIterator is the well-known symbol used by asynchronous iterables.

See Symbol.asyncIterator on MDN.

description

RESCRIPT
let description: t => option<string>

description

Returns Some(string) containing the description of this symbol, or None if the symbol has no description.

Examples

RESCRIPT
let sym = Symbol.make("sym1") Symbol.description(sym) == Some("sym1")

getFor

RESCRIPT
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

RESCRIPT
Symbol.getFor("sym1") == Symbol.getFor("sym1")

hasInstance

RESCRIPT
let hasInstance: t

hasInstance is used by custom instanceof checks.

See Symbol.hasInstance on MDN.

ignore

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

isConcatSpreadable

RESCRIPT
let isConcatSpreadable: t

isConcatSpreadable controls whether objects are flattened when passed to Array.concat.

See Symbol.isConcatSpreadable on MDN.

iterator

RESCRIPT
let iterator: t

iterator is returned by objects that can be iterated with for..of.

See Symbol.iterator on MDN.

keyFor

RESCRIPT
let keyFor: t => option<string>

keyFor(key)

Retrieves a shared Symbol key from the global Symbol registry for the given Symbol.

Examples

RESCRIPT
let globalSym = Symbol.getFor("sym1") // Global symbol globalSym->Option.flatMap(Symbol.description) == Some("sym1")

make

RESCRIPT
let make: string => t

make(key)

Makes a new unique Symbol value.

Examples

RESCRIPT
Symbol.make("sym1")->Symbol.description == Some("sym1")

match

RESCRIPT
let match: t

match customises how values respond to String.prototype.match.

See Symbol.match on MDN.

matchAll

RESCRIPT
let matchAll: t

matchAll customises how values respond to String.prototype.matchAll.

See Symbol.matchAll on MDN.

replace

RESCRIPT
let replace: t

replace customises how values respond to String.prototype.replace.

See Symbol.replace on MDN.

RESCRIPT
let search: t

search customises how values respond to String.prototype.search.

See Symbol.search on MDN.

species

RESCRIPT
let species: t

species lets constructors return a different derived constructor when methods create new instances.

See Symbol.species on MDN.

split

RESCRIPT
let split: t

split customises how values respond to String.prototype.split.

See Symbol.split on MDN.

t

RESCRIPT
type t

Type representing a Symbol.

toPrimitive

RESCRIPT
let toPrimitive: t

toPrimitive customises how objects convert to primitive values.

See Symbol.toPrimitive on MDN.

toString

RESCRIPT
let toString: t => string

toString

// Returns a string representing this symbol value.

Examples

RESCRIPT
let sym = Symbol.make("sym1") Symbol.toString(sym) == "Symbol(sym1)"

toStringTag

RESCRIPT
let toStringTag: t

toStringTag customises the default tag shown by Object.prototype.toString.

See Symbol.toStringTag on MDN.

unscopables

RESCRIPT
let unscopables: t

unscopables marks properties that should be skipped by with.

See Symbol.unscopables on MDN.