Symbol

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

Compiles to a regular JavaScript Symbol.

asyncIterator

RES
let asyncIterator: t

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

See Symbol.asyncIterator on MDN.

description

RES
let description: t => option<string>

description

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

Examples

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

getFor

RES
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

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

hasInstance

RES
let hasInstance: t

hasInstance is used by custom instanceof checks.

See Symbol.hasInstance on MDN.

ignore

RES
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

RES
let isConcatSpreadable: t

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

See Symbol.isConcatSpreadable on MDN.

iterator

RES
let iterator: t

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

See Symbol.iterator on MDN.

keyFor

RES
let keyFor: t => option<string>

keyFor(key)

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

Examples

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

make

RES
let make: string => t

make(key)

Makes a new unique Symbol value.

Examples

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

match

RES
let match: t

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

See Symbol.match on MDN.

matchAll

RES
let matchAll: t

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

See Symbol.matchAll on MDN.

replace

RES
let replace: t

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

See Symbol.replace on MDN.

RES
let search: t

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

See Symbol.search on MDN.

species

RES
let species: t

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

See Symbol.species on MDN.

split

RES
let split: t

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

See Symbol.split on MDN.

t

RES
type t

Type representing a Symbol.

toPrimitive

RES
let toPrimitive: t

toPrimitive customises how objects convert to primitive values.

See Symbol.toPrimitive on MDN.

toString

RES
let toString: t => string

toString

// Returns a string representing this symbol value.

Examples

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

toStringTag

RES
let toStringTag: t

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

See Symbol.toStringTag on MDN.

unscopables

RES
let unscopables: t

unscopables marks properties that should be skipped by with.

See Symbol.unscopables on MDN.