Skip to main content

Record

A collection of functions to manipulate Record

Index

Accessor

get

  • get<Key, Value>(record: Record<Key, Value>, key: Key): Option<Value>
  • Return an Option of value for the given key

    @example
    const record = { myProperty: 'myValue' };
    Record.get(record, 'myProperty'); // Option.Some('myValue')
    Record.get(record, 'nonExistent'); // Option.None

    Type parameters

size

  • size<D>(record: D): Int
  • Return the number of entries in the record

    @example
    const record = { first: 1, second: 2 };
    Record.size(record); // 2

    Type parameters

Constructor

empty

  • empty<Key, Value>(): Record<Key, Value>
  • Return an empty Record

    @example
    const empty = Record.empty(); // frozen {}

    Type parameters

from

  • from<Key, Value>(iterable: Iterable<[Key, Value], any, any>): Record<Key, Value>
  • Return a new Record from an iterable of [key, value]

    @example
    const record = Record.from([['a', 1], ['b', 2]]); // frozen { a: 1, b: 2}

    Type parameters

Other

delete

  • delete<Key, Value>(record: Record<Key, Value>, key: Key): Record<Key, Value>
  • Return a new record without the key

    @example
    const record = { myProperty: 'myValue' };
    Record.delete(record, 'myProperty'); // {}

    Type parameters

entries

  • entries<Key, Value>(record: Record<Key, Value>): Iterable<[Key, Value]>
  • Return an iterator over all [key, value]

    @example
    const record = { first: 1, second: 2 };
    Array.from(Record.entries(record)); // [['first', 1], ['second', 2]]

    Type parameters

forEach

  • forEach<Key, Value, D>(record: D, fn: (value: Value, key: Key, record: D) => unknown): void
  • Call fn(value, key, record) on each entries in the record

    @example
    const record = { first: 1, second: 2 };
    Record.forEach(record, (value, key, record) => {
    // call (1, 'first', record)
    // call (2, 'second', record)
    }); // 2

    Type parameters

has

  • has<Key>(record: Record<Key, any>, key: Key): boolean
  • Return true if record contains key

    @example
    const record = { myProperty: 'myValue' };
    Record.has(record, 'myProperty'); // true
    Record.has(record, 'nonExistent'); // false

    Type parameters

keys

  • keys<Key>(record: Record<Key, any>): Iterable<Key>
  • Return an iterator over all keys

    @example
    const record = { first: 1, second: 2 };
    Array.from(Record.keys(record)); // ['first', 'second']

    Type parameters

set

  • set<Key, Value>(record: Record<Key, Value>, key: Key, value: Value): Record<Key, Value>
  • Return a new record including the new [key, value]

    @example
    const record = { myProperty: 'myValue' };
    Record.set(record, 'myOtherProperty', 'myOtherValue'); // { myProperty: 'myValue', myOtherProperty: 'myOtherValue' }

    Type parameters

values

  • values<Key, Value>(record: Record<Key, Value>): Iterable<Value>
  • Return an iterator over all values

    @example
    const record = { first: 1, second: 2 };
    Array.from(Record.entries(record)); // [1, 2]

    Type parameters