<K extends string, A>(self: ReadonlyRecord<K, A>): Array<[K, A]>Takes a record and returns an array of tuples containing its keys and values.
Example (Converting a record to entries)
import { Record } from "effect"
import * as assert from "node:assert"
const x = { a: 1, b: 2, c: 3 }
assert.deepStrictEqual(Record.toEntries(x), [["a", 1], ["b", 2], ["c", 3]])converting
Source effect/Record.ts:3634 lines
export const const toEntries: <K extends string, A>(
self: ReadonlyRecord<K, A>
) => Array<[K, A]>
Takes a record and returns an array of tuples containing its keys and values.
Example (Converting a record to entries)
import { Record } from "effect"
import * as assert from "node:assert"
const x = { a: 1, b: 2, c: 3 }
assert.deepStrictEqual(Record.toEntries(x), [["a", 1], ["b", 2], ["c", 3]])
toEntries: <function (type parameter) K in <K extends string, A>(self: ReadonlyRecord<K, A>): Array<[K, A]>K extends string, function (type parameter) A in <K extends string, A>(self: ReadonlyRecord<K, A>): Array<[K, A]>A>(self: ReadonlyRecord<K, A>self: type ReadonlyRecord<in out K extends string | symbol, out A> = { readonly [P in K]: A; }Represents a readonly record with keys of type K and values of type A.
This is the foundational type for immutable key-value mappings in Effect.
Example (Defining a readonly record type)
import type { Record } from "effect"
// Creating a readonly record type
type UserRecord = Record.ReadonlyRecord<"name" | "age", string | number>
const user: UserRecord = {
name: "John",
age: 30
}
Namespace containing utility types for working with readonly records.
These types help with type-level operations on record keys and values.
Example (Using readonly record helper types)
import type { Record } from "effect"
// Using NonLiteralKey to convert literal keys to generic types
type GenericKey = Record.ReadonlyRecord.NonLiteralKey<"foo" | "bar"> // string
// Using IntersectKeys to find common keys between record types
type CommonKeys = Record.ReadonlyRecord.IntersectKeys<"a" | "b", "b" | "c"> // "b"
ReadonlyRecord<function (type parameter) K in <K extends string, A>(self: ReadonlyRecord<K, A>): Array<[K, A]>K, function (type parameter) A in <K extends string, A>(self: ReadonlyRecord<K, A>): Array<[K, A]>A>) => interface Array<T>Array<[function (type parameter) K in <K extends string, A>(self: ReadonlyRecord<K, A>): Array<[K, A]>K, function (type parameter) A in <K extends string, A>(self: ReadonlyRecord<K, A>): Array<[K, A]>A]> = const collect: {
<K extends string, A, B>(
f: (key: K, a: A) => B
): (self: ReadonlyRecord<K, A>) => Array<B>
<K extends string, A, B>(
self: ReadonlyRecord<K, A>,
f: (key: K, a: A) => B
): Array<B>
}
collect((
key: K extends stringkey,
value: Avalue
) => [key: K extends stringkey, value: Avalue])Referenced by 1 symbols