<K extends string, A>(self: ReadonlyRecord<K, Option.Option<A>>): Record<
ReadonlyRecord.NonLiteralKey<K>,
A
>Returns a new record containing only the Some values from a record of
Option values, preserving the original keys.
Example (Extracting Some values)
import { Option, Record } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(
Record.getSomes({ a: Option.some(1), b: Option.none(), c: Option.some(2) }),
{ a: 1, c: 2 }
)export const const getSomes: <K extends string, A>(
self: ReadonlyRecord<K, Option.Option<A>>
) => Record<ReadonlyRecord.NonLiteralKey<K>, A>
Returns a new record containing only the Some values from a record of
Option values, preserving the original keys.
Example (Extracting Some values)
import { Option, Record } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(
Record.getSomes({ a: Option.some(1), b: Option.none(), c: Option.some(2) }),
{ a: 1, c: 2 }
)
getSomes: <function (type parameter) K in <K extends string, A>(self: ReadonlyRecord<K, Option.Option<A>>): Record<ReadonlyRecord.NonLiteralKey<K>, A>K extends string, function (type parameter) A in <K extends string, A>(self: ReadonlyRecord<K, Option.Option<A>>): Record<ReadonlyRecord.NonLiteralKey<K>, A>A>(
self: ReadonlyRecord<K, Option.Option<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, Option.Option<A>>): Record<ReadonlyRecord.NonLiteralKey<K>, A>K, import OptionOption.type Option.Option = /*unresolved*/ anyOption<function (type parameter) A in <K extends string, A>(self: ReadonlyRecord<K, Option.Option<A>>): Record<ReadonlyRecord.NonLiteralKey<K>, A>A>>
) => type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<ReadonlyRecord.type ReadonlyRecord<in out K extends string | symbol, out A>.NonLiteralKey<K extends string | symbol> = K extends string ? ReadonlyRecord.IsFiniteString<K> extends true ? string : K : symbolRepresents a type that converts literal string keys to generic string type and symbol keys to generic symbol type.
This is useful for maintaining type safety while allowing flexible key types in record operations.
Example (Converting literal keys to non-literal keys)
import type { Record } from "effect"
// For literal string keys, this becomes 'string'
type Example1 = Record.ReadonlyRecord.NonLiteralKey<"foo" | "bar"> // string
// For symbol keys, this becomes 'symbol'
type Example2 = Record.ReadonlyRecord.NonLiteralKey<symbol> // symbol
NonLiteralKey<function (type parameter) K in <K extends string, A>(self: ReadonlyRecord<K, Option.Option<A>>): Record<ReadonlyRecord.NonLiteralKey<K>, A>K>, function (type parameter) A in <K extends string, A>(self: ReadonlyRecord<K, Option.Option<A>>): Record<ReadonlyRecord.NonLiteralKey<K>, A>A> = <function (type parameter) K in <K extends string, A>(self: ReadonlyRecord<K, Option.Option<A>>): Record<ReadonlyRecord.NonLiteralKey<K>, A>K extends string, function (type parameter) A in <K extends string, A>(self: ReadonlyRecord<K, Option.Option<A>>): Record<ReadonlyRecord.NonLiteralKey<K>, A>A>(
self: ReadonlyRecord<K, Option.Option<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, Option.Option<A>>): Record<ReadonlyRecord.NonLiteralKey<K>, A>K, import OptionOption.type Option.Option = /*unresolved*/ anyOption<function (type parameter) A in <K extends string, A>(self: ReadonlyRecord<K, Option.Option<A>>): Record<ReadonlyRecord.NonLiteralKey<K>, A>A>>
): type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<ReadonlyRecord.type ReadonlyRecord<in out K extends string | symbol, out A>.NonLiteralKey<K extends string | symbol> = K extends string ? ReadonlyRecord.IsFiniteString<K> extends true ? string : K : symbolRepresents a type that converts literal string keys to generic string type and symbol keys to generic symbol type.
This is useful for maintaining type safety while allowing flexible key types in record operations.
Example (Converting literal keys to non-literal keys)
import type { Record } from "effect"
// For literal string keys, this becomes 'string'
type Example1 = Record.ReadonlyRecord.NonLiteralKey<"foo" | "bar"> // string
// For symbol keys, this becomes 'symbol'
type Example2 = Record.ReadonlyRecord.NonLiteralKey<symbol> // symbol
NonLiteralKey<function (type parameter) K in <K extends string, A>(self: ReadonlyRecord<K, Option.Option<A>>): Record<ReadonlyRecord.NonLiteralKey<K>, A>K>, function (type parameter) A in <K extends string, A>(self: ReadonlyRecord<K, Option.Option<A>>): Record<ReadonlyRecord.NonLiteralKey<K>, A>A> => {
const const out: Record<string, A>out: type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, function (type parameter) A in <K extends string, A>(self: ReadonlyRecord<K, Option.Option<A>>): Record<ReadonlyRecord.NonLiteralKey<K>, A>A> = const empty: <string, A>() => Record<
string,
A
>
Creates a new, empty record.
Example (Creating an empty record)
import { Record } from "effect"
// Create an empty record
const emptyRecord = Record.empty<string, number>()
console.log(emptyRecord) // {}
// The type ensures type safety for future operations
const withValue = Record.set(emptyRecord, "count", 42)
console.log(withValue) // { count: 42 }
empty()
for (const const key: K extends stringkey of const keys: <
K extends string | symbol,
A
>(
self: ReadonlyRecord<K, A>
) => Array<K & string>
Retrieves the keys of a given record as an array.
Example (Getting record keys)
import { Record } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(Record.keys({ a: 1, b: 2, c: 3 }), ["a", "b", "c"])
keys(self: ReadonlyRecord<K, Option.Option<A>>self)) {
const const option: ReadonlyRecord<
K,
Option.Option<A>
>[K]
option = self: ReadonlyRecord<K, Option.Option<A>>self[const key: K extends stringkey]
if (import OptionOption.isSome(const option: Option.Option<A>option)) {
const out: Record<string, A>out[const key: K extends stringkey] = const option: Option.Some<A>const option: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
option.value
}
}
return const out: Record<string, A>out
}