Rec
constRec:object
Defined in: Data/Rec.ts:601
Type Declaration
Section titled “Type Declaration”compact
Section titled “compact”compact: <
A>(data) =>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”Readonly<Record<string, Maybe<A>>>
Returns
Section titled “Returns”Readonly<Record<string, A>>
Example
Section titled “Example”entries
Section titled “entries”entries: <
T>(data) => 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”T
Returns
Section titled “Returns”readonly readonly [keyof T, T[keyof T]][]
Example
Section titled “Example”filter
Section titled “filter”filter: <
A>(predicate) => (data) =>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”(a) => boolean
Returns
Section titled “Returns”(data) => Readonly<Record<string, A>>
Example
Section titled “Example”filterMap
Section titled “filterMap”filterMap: <
A,B>(f) => (data) =>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”(a) => Maybe<B>
Returns
Section titled “Returns”(data) => Readonly<Record<string, B>>
Example
Section titled “Example”filterWithKey
Section titled “filterWithKey”filterWithKey: <
A>(predicate) => (data) =>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, a) => boolean
Returns
Section titled “Returns”(data) => Readonly<Record<string, A>>
Example
Section titled “Example”from:
object=RecFrom
from.entries
Section titled “from.entries”entries: <
A>(data) =>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>(keyFn) => (items) =>Readonly<Record<string, readonlyA[]>>
Groups elements of an array into a record keyed by the result of keyFn. 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”(a) => 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>(data) =>boolean
Returns true if the record has no keys.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”Readonly<Record<string, A>>
Returns
Section titled “Returns”boolean
Example
Section titled “Example”is.nonEmpty
Section titled “is.nonEmpty”nonEmpty: <
A,K>(data) =>data 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”Readonly<Record<K, A>>
Returns
Section titled “Returns”data is NonEmptyRecord<A, K>
Example
Section titled “Example”keys: <
T>(data) => readonly keyofT&string[]
Returns all keys of a record.
Type Parameters
Section titled “Type Parameters”T extends Record<string, unknown>
Parameters
Section titled “Parameters”T
Returns
Section titled “Returns”readonly keyof T & string[]
Example
Section titled “Example”lookup
Section titled “lookup”lookup: <
K>(key) => <V>(data) =>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>(data) => Maybe<V>
Example
Section titled “Example”map: <
A,B>(f) => <K>(data) =>Readonly<Record<K,B>>
Transforms each value in a record.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(a) => B
Returns
Section titled “Returns”<K>(data) => Readonly<Record<K, B>>
Example
Section titled “Example”mapEntries
Section titled “mapEntries”mapEntries: <
A,K2,B>(f) => (data) =>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”(key, value) => readonly [K2, B]
Returns
Section titled “Returns”(data) => Readonly<Record<K2, B>>
Example
Section titled “Example”mapKeys
Section titled “mapKeys”mapKeys: (
f) => <A>(data) =>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”(key) => string
Returns
Section titled “Returns”<A>(data) => Readonly<Record<string, A>>
Example
Section titled “Example”mapWithKey
Section titled “mapWithKey”mapWithKey: <
A,B>(f) => <K>(data) =>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”(key, a) => B
Returns
Section titled “Returns”<K>(data) => Readonly<Record<K, B>>
Example
Section titled “Example”merge: <
A>(other) => (data) =>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”(data) => Readonly<Record<string, A>>
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”(a, b) => A
Returns
Section titled “Returns”{(second): (first) => Readonly<Record<string, A>>; (first, second): Readonly<Record<string, A>>; }
Example
Section titled “Example”NonEmpty
Section titled “NonEmpty”NonEmpty:
object=RecNonEmpty
NonEmpty.entries
Section titled “NonEmpty.entries”entries: <
K,A>(data) =>NonEmptyArr<readonly [K,A]>
Type Parameters
Section titled “Type Parameters”K extends string
A
Parameters
Section titled “Parameters”NonEmptyRecord<A, K>
Returns
Section titled “Returns”NonEmptyArr<readonly [K, A]>
NonEmpty.from
Section titled “NonEmpty.from”from:
object
NonEmpty.from.Record
Section titled “NonEmpty.from.Record”Record: <
K,A>(data) =>Maybe<NonEmptyRecord<A,K>>
Type Parameters
Section titled “Type Parameters”K extends string
A
Parameters
Section titled “Parameters”Readonly<Record<K, A>>
Returns
Section titled “Returns”Maybe<NonEmptyRecord<A, K>>
NonEmpty.keys
Section titled “NonEmpty.keys”keys: <
K,A>(data) =>NonEmptyArr<K>
Type Parameters
Section titled “Type Parameters”K extends string
A
Parameters
Section titled “Parameters”NonEmptyRecord<A, K>
Returns
Section titled “Returns”NonEmptyArr<K>
NonEmpty.map
Section titled “NonEmpty.map”map: <
A,B>(f) => <K>(data) =>NonEmptyRecord<B,K>
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(a) => B
Returns
Section titled “Returns”<K>(data) => NonEmptyRecord<B, K>
NonEmpty.mapWithKey
Section titled “NonEmpty.mapWithKey”mapWithKey: <
A,B>(f) => <K>(data) =>NonEmptyRecord<B,K>
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(key, a) => B
Returns
Section titled “Returns”<K>(data) => NonEmptyRecord<B, K>
NonEmpty.reduce
Section titled “NonEmpty.reduce”reduce: <
A>(f) => <K>(data) =>A
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”(acc, a) => A
Returns
Section titled “Returns”<K>(data) => A
NonEmpty.singleton
Section titled “NonEmpty.singleton”singleton: <
K,A>(key,value) =>NonEmptyRecord<A,K>
Type Parameters
Section titled “Type Parameters”K extends string
A
Parameters
Section titled “Parameters”K
A
Returns
Section titled “Returns”NonEmptyRecord<A, K>
NonEmpty.values
Section titled “NonEmpty.values”values: <
K,A>(data) =>NonEmptyArr<A>
Type Parameters
Section titled “Type Parameters”K extends string
A
Parameters
Section titled “Parameters”NonEmptyRecord<A, K>
Returns
Section titled “Returns”NonEmptyArr<A>
omit: <
K>(…omittedKeys) => <A>(data) =>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”…K[]
Returns
Section titled “Returns”<A>(data) => Omit<A, K>
Example
Section titled “Example”pick: <
K>(…pickedKeys) => <A>(data) =>Pick<A,K>
Picks specific keys from a record.
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”pickedKeys
Section titled “pickedKeys”…K[]
Returns
Section titled “Returns”<A>(data) => Pick<A, K>
Example
Section titled “Example”sequence
Section titled “sequence”sequence:
object
sequence.Maybe
Section titled “sequence.Maybe”Maybe: <
A>(data) =>Maybe<Readonly<Record<string,A>>> =RecMaybe.sequence
Sequence a record of Maybe values into a Maybe of a record.
If any key contains None, the entire operation returns None.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”Readonly<Record<string, Maybe<A>>>
Returns
Section titled “Returns”Maybe<Readonly<Record<string, A>>>
Example
Section titled “Example”sequence.Result
Section titled “sequence.Result”Result: <
E,A>(data) =>Result<E,Readonly<Record<string,A>>> =RecResult.sequence
Sequence a record of Result values into a Result of a record.
If any key contains an Err, the entire operation returns that Err.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”Readonly<Record<string, Result<E, A>>>
Returns
Section titled “Returns”Result<E, Readonly<Record<string, A>>>
Example
Section titled “Example”size: <
A>(data) =>number
Returns the number of keys in a record.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”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>(data) =>ReadonlyMap<K,A>
Type Parameters
Section titled “Type Parameters”A
K extends string = string
Parameters
Section titled “Parameters”Readonly<Record<K, A>>
Returns
Section titled “Returns”ReadonlyMap<K, A>
traverse
Section titled “traverse”traverse:
object
traverse.Maybe
Section titled “traverse.Maybe”Maybe: <
A,B>(f) => (data) =>Maybe<Readonly<Record<string,B>>> =RecMaybe.traverse
Map a function that returns a Maybe over each value of a record,
and combine the results into a single Maybe containing the updated record.
If any value results in None, the entire operation returns None (short-circuits).
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(a) => Maybe<B>
Returns
Section titled “Returns”(data) => Maybe<Readonly<Record<string, B>>>
Example
Section titled “Example”traverse.Result
Section titled “traverse.Result”Result: <
E,A,B>(f) => (data) =>Result<E,Readonly<Record<string,B>>> =RecResult.traverse
Map a function that returns a Result over each value of a record,
and combine the results into a single Result containing the updated record.
If any value results in an Err, the entire operation returns that Err (short-circuits).
Type Parameters
Section titled “Type Parameters”E
A
B
Parameters
Section titled “Parameters”(a) => Result<E, B>
Returns
Section titled “Returns”(data) => Result<E, Readonly<Record<string, B>>>
Example
Section titled “Example”updateIn
Section titled “updateIn”updateIn: <
T>(path,f) => (data) =>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]
(val) => T
Returns
Section titled “Returns”(data) => Readonly<Record<string, unknown>>
Example
Section titled “Example”values
Section titled “values”values: <
T>(data) => readonlyT[keyofT&string][]
Returns all values of a record.
Type Parameters
Section titled “Type Parameters”T extends Record<string, unknown>
Parameters
Section titled “Parameters”T
Returns
Section titled “Returns”readonly T[keyof T & string][]