Rec
constRec:object
Defined in: Data/Rec.ts:704
Type Declaration
Section titled “Type Declaration”compact
Section titled “compact”compact: <
A>(record) =>Readonly<Record<string,A>>
Removes all None values from a Record<string, Maybe<A>>, returning a plain Record<string, A>.
Useful when building records from fallible lookups.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”record
Section titled “record”Readonly<Record<string, Maybe<A>>>
Returns
Section titled “Returns”Readonly<Record<string, A>>
Example
Section titled “Example”entries
Section titled “entries”entries: <
T>(record) => readonly (readonly [keyofT,T[keyofT]])[]
Returns all key-value pairs of a record.
Type Parameters
Section titled “Type Parameters”T extends Record<string, unknown>
Parameters
Section titled “Parameters”record
Section titled “record”T
Returns
Section titled “Returns”readonly (readonly [keyof T, T[keyof T]])[]
Example
Section titled “Example”filter
Section titled “filter”filter: <
A>(predicate) => (record) =>Readonly<Record<string,A>>
Filters values in a record by a predicate.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(value) => boolean
Returns
Section titled “Returns”(record) => Readonly<Record<string, A>>
- filterWithKey for filtering values with key access.
- filterMap for filtering and mapping in a single pass.
Example
Section titled “Example”filterMap
Section titled “filterMap”filterMap: <
A,B>(transform) => (record) =>Readonly<Record<string,B>>
Maps each value in a record with a function returning a Maybe, keeping only Some values.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(value) => Maybe<B>
Returns
Section titled “Returns”(record) => Readonly<Record<string, B>>
filter for filtering with a boolean predicate.
Example
Section titled “Example”filterWithKey
Section titled “filterWithKey”filterWithKey: <
A>(predicate) => (record) =>Readonly<Record<string,A>>
Filters values in a record by a predicate that also receives the key.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(key, value) => boolean
Returns
Section titled “Returns”(record) => Readonly<Record<string, A>>
filter for filtering values without key access.
Example
Section titled “Example”from:
object=RecFrom
from.entries
Section titled “from.entries”entries: <
A>(pairs) =>Readonly<Record<string,A>>
Creates a record from key-value pairs.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly (readonly [string, A])[]
Returns
Section titled “Returns”Readonly<Record<string, A>>
Example
Section titled “Example”groupBy
Section titled “groupBy”groupBy: <
A>(keySelector) => (items) =>Readonly<Record<string, readonlyA[]>>
Groups elements of an array into a record keyed by the result of keySelector. Each key maps to
the array of elements that produced it, in insertion order.
Unlike Dict.groupBy, keys are always strings. Use Dict.groupBy when you need non-string
keys or want to avoid the plain-object prototype chain.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”keySelector
Section titled “keySelector”(item) => string
Returns
Section titled “Returns”(items) => Readonly<Record<string, readonly A[]>>
Example
Section titled “Example”is:
object=RecIs
is.empty
Section titled “is.empty”empty: <
A>(record) =>boolean
Returns true if the record has no keys.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”record
Section titled “record”Readonly<Record<string, A>>
Returns
Section titled “Returns”boolean
nonEmpty for checking if a record has keys.
Example
Section titled “Example”is.nonEmpty
Section titled “is.nonEmpty”nonEmpty: <
A,K>(record) =>record is NonEmptyRecord<A, K>=_isNonEmpty
Type guard to check if a record is non-empty.
Type Parameters
Section titled “Type Parameters”A
K extends string
Parameters
Section titled “Parameters”record
Section titled “record”Readonly<Record<K, A>>
Returns
Section titled “Returns”record is NonEmptyRecord<A, K>
empty for checking if a record has no keys.
Example
Section titled “Example”keys: <
T>(record) => readonly (keyofT&string)[]
Returns all keys of a record.
Type Parameters
Section titled “Type Parameters”T extends Record<string, unknown>
Parameters
Section titled “Parameters”record
Section titled “record”T
Returns
Section titled “Returns”readonly (keyof T & string)[]
Example
Section titled “Example”lookup
Section titled “lookup”lookup: <
K>(key) => <V>(record) =>Maybe<V>
Looks up a value by key, returning Maybe.
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”<V>(record) => Maybe<V>
Example
Section titled “Example”map: <
A,B>(transform) => <K>(record) =>Readonly<Record<K,B>>
Transforms each value in a record.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(value) => B
Returns
Section titled “Returns”<K>(record) => Readonly<Record<K, B>>
- mapWithKey for transforming values with key access.
- mapKeys for transforming keys while preserving values.
- mapEntries for transforming keys and values simultaneously.
Example
Section titled “Example”mapEntries
Section titled “mapEntries”mapEntries: <
A,K2,B>(transform) => (record) =>Readonly<Record<K2,B>>
Transforms key and value pairs simultaneously.
Type Parameters
Section titled “Type Parameters”A
K2 extends string
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(key, value) => readonly [K2, B]
Returns
Section titled “Returns”(record) => Readonly<Record<K2, B>>
Example
Section titled “Example”mapKeys
Section titled “mapKeys”mapKeys: (
transform) => <A>(record) =>Readonly<Record<string,A>>
Transforms each key while preserving values. If two keys map to the same new key, the last one wins.
Parameters
Section titled “Parameters”transform
Section titled “transform”(key) => string
Returns
Section titled “Returns”<A>(record) => Readonly<Record<string, A>>
- map for transforming values.
- mapEntries for transforming keys and values simultaneously.
Example
Section titled “Example”mapWithKey
Section titled “mapWithKey”mapWithKey: <
A,B>(transform) => <K>(record) =>Readonly<Record<K,B>>
Transforms each value in a record, also receiving the key.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(key, value) => B
Returns
Section titled “Returns”<K>(record) => Readonly<Record<K, B>>
map for transforming values without key access.
Example
Section titled “Example”merge: <
A>(other) => (record) =>Readonly<Record<string,A>>
Merges two records. Values from the second record take precedence.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”Readonly<Record<string, A>>
Returns
Section titled “Returns”(record) => Readonly<Record<string, A>>
mergeWith for merging records with custom collision resolution.
Example
Section titled “Example”mergeWith
Section titled “mergeWith”mergeWith: <
A>(combine) => {(second): (first) =>Readonly<Record<string,A>>; (first,second):Readonly<Record<string,A>>; }
Merges two records using a custom combination function on key collisions.
Supports both uncurried Rec.mergeWith(combine)(first, second) and curried pipe(first, Rec.mergeWith(combine)(second)).
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”combine
Section titled “combine”(first, second) => A
Returns
Section titled “Returns”{(second): (first) => Readonly<Record<string, A>>; (first, second): Readonly<Record<string, A>>; }
merge for shallow merging with right-precedence.
Example
Section titled “Example”NonEmpty
Section titled “NonEmpty”NonEmpty:
object=RecNonEmpty
Utilities for working with guaranteed non-empty records (NonEmptyRecord).
NonEmpty.entries
Section titled “NonEmpty.entries”entries: <
K,A>(record) =>NonEmptyArr<readonly [K,A]>
Returns all entries of a non-empty record as a NonEmptyArr.
Type Parameters
Section titled “Type Parameters”K extends string
A
Parameters
Section titled “Parameters”record
Section titled “record”NonEmptyRecord<A, K>
Returns
Section titled “Returns”NonEmptyArr<readonly [K, A]>
Example
Section titled “Example”NonEmpty.from
Section titled “NonEmpty.from”from:
object
NonEmpty.from.record
Section titled “NonEmpty.from.record”record: <
K,A>(record) =>Maybe<NonEmptyRecord<A,K>>
Refines a standard record to a NonEmptyRecord, returning Some if it has keys, None otherwise.
Type Parameters
Section titled “Type Parameters”K extends string
A
Parameters
Section titled “Parameters”record
Section titled “record”Readonly<Record<K, A>>
Returns
Section titled “Returns”Maybe<NonEmptyRecord<A, K>>
Example
Section titled “Example”NonEmpty.keys
Section titled “NonEmpty.keys”keys: <
K,A>(record) =>NonEmptyArr<K>
Returns all keys of a non-empty record as a NonEmptyArr.
Type Parameters
Section titled “Type Parameters”K extends string
A
Parameters
Section titled “Parameters”record
Section titled “record”NonEmptyRecord<A, K>
Returns
Section titled “Returns”NonEmptyArr<K>
Example
Section titled “Example”NonEmpty.map
Section titled “NonEmpty.map”map: <
A,B>(transform) => <K>(record) =>NonEmptyRecord<B,K>
Transforms each value of a non-empty record, preserving non-emptiness.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(value) => B
Returns
Section titled “Returns”<K>(record) => NonEmptyRecord<B, K>
Example
Section titled “Example”NonEmpty.mapWithKey
Section titled “NonEmpty.mapWithKey”mapWithKey: <
A,B>(transform) => <K>(record) =>NonEmptyRecord<B,K>
Transforms each value of a non-empty record with key access, preserving non-emptiness.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(key, value) => B
Returns
Section titled “Returns”<K>(record) => NonEmptyRecord<B, K>
Example
Section titled “Example”NonEmpty.reduce
Section titled “NonEmpty.reduce”reduce: <
A>(reducer) => <K>(record) =>A
Reduces the values of a non-empty record using the first value as the initial accumulator.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”reducer
Section titled “reducer”(accumulator, value) => A
Returns
Section titled “Returns”<K>(record) => A
Example
Section titled “Example”NonEmpty.singleton
Section titled “NonEmpty.singleton”singleton: <
K,A>(key,value) =>NonEmptyRecord<A,K>
Creates a NonEmptyRecord containing a single key-value entry.
Type Parameters
Section titled “Type Parameters”K extends string
A
Parameters
Section titled “Parameters”K
A
Returns
Section titled “Returns”NonEmptyRecord<A, K>
Example
Section titled “Example”NonEmpty.values
Section titled “NonEmpty.values”values: <
K,A>(record) =>NonEmptyArr<A>
Returns all values of a non-empty record as a NonEmptyArr.
Type Parameters
Section titled “Type Parameters”K extends string
A
Parameters
Section titled “Parameters”record
Section titled “record”NonEmptyRecord<A, K>
Returns
Section titled “Returns”NonEmptyArr<A>
Example
Section titled “Example”omit: <
K>(…omittedKeys) => <A>(record) =>Omit<A,K>
Omits specific keys from a record.
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”omittedKeys
Section titled “omittedKeys”…readonly K[]
Returns
Section titled “Returns”<A>(record) => Omit<A, K>
pick for retaining only specific keys from a record.
Example
Section titled “Example”pick: <
K>(…pickedKeys) => <A>(record) =>Pick<A,K& keyofA>
Picks specific keys from a record.
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”pickedKeys
Section titled “pickedKeys”…readonly K[]
Returns
Section titled “Returns”<A>(record) => Pick<A, K & keyof A>
omit for removing specific keys from a record.
Example
Section titled “Example”sequence
Section titled “sequence”sequence:
object
Sequences a record of effectful containers into a container of record.
sequence.Maybe
Section titled “sequence.Maybe”Maybe: <
A>(record) =>Maybe<Readonly<Record<string,A>>> =sequenceMaybe
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”record
Section titled “record”Readonly<Record<string, Maybe<A>>>
Returns
Section titled “Returns”Maybe<Readonly<Record<string, A>>>
sequence.Result
Section titled “sequence.Result”Result: <
E,A>(record) =>Result<E,Readonly<Record<string,A>>> =sequenceResult
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”record
Section titled “record”Readonly<Record<string, Result<E, A>>>
Returns
Section titled “Returns”Result<E, Readonly<Record<string, A>>>
size: <
A>(record) =>number
Returns the number of keys in a record.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”record
Section titled “record”Readonly<Record<string, A>>
Returns
Section titled “Returns”number
Example
Section titled “Example”to:
object=RecTo
to.Dict
Section titled “to.Dict”Dict: <
A,K>(record) =>ReadonlyMap<K,A>
Converts a record to a ReadonlyMap.
Type Parameters
Section titled “Type Parameters”A
K extends string = string
Parameters
Section titled “Parameters”record
Section titled “record”Readonly<Record<K, A>>
Returns
Section titled “Returns”ReadonlyMap<K, A>
Example
Section titled “Example”traverse
Section titled “traverse”traverse:
object
Maps record values to an effectful container and aggregates the results into a record.
traverse.Maybe
Section titled “traverse.Maybe”Maybe: <
A,B>(transform) => (record) =>Maybe<Readonly<Record<string,B>>> =traverseMaybe
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(value) => Maybe<B>
Returns
Section titled “Returns”(record) => Maybe<Readonly<Record<string, B>>>
traverse.Result
Section titled “traverse.Result”Result: <
E,A,B>(transform) => (record) =>Result<E,Readonly<Record<string,B>>> =traverseResult
Type Parameters
Section titled “Type Parameters”E
A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(value) => Result<E, B>
Returns
Section titled “Returns”(record) => Result<E, Readonly<Record<string, B>>>
updateIn
Section titled “updateIn”updateIn: <
T>(path,transform) => (record) =>Readonly<Record<string,unknown>>
Immutably updates a value at a deep nested path inside a record.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”readonly [string, string]
transform
Section titled “transform”(value) => T
Returns
Section titled “Returns”(record) => Readonly<Record<string, unknown>>
Example
Section titled “Example”values
Section titled “values”values: <
T>(record) => readonlyT[keyofT&string][]
Returns all values of a record.
Type Parameters
Section titled “Type Parameters”T extends Record<string, unknown>
Parameters
Section titled “Parameters”record
Section titled “record”T
Returns
Section titled “Returns”readonly T[keyof T & string][]