<K extends string, A>(that: ReadonlyRecord<K, A>): (
self: ReadonlyRecord<K, A>
) => boolean
<K extends string, A>(
self: ReadonlyRecord<K, A>,
that: ReadonlyRecord<K, A>
): booleanChecks whether the first record is a subrecord of the second record.
Details
Returns true when every key and value in self is also present in that.
Values are compared with Effect equality via Equal.asEquivalence().
Example (Checking subrecords)
import { Record } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(
Record.isSubrecord({ a: 1 } as Record<string, number>, { a: 1, b: 2 }),
true
)
assert.deepStrictEqual(
Record.isSubrecord({ a: 1, b: 2 }, { a: 1 } as Record<string, number>),
false
)export const const isSubrecord: {
<K extends string, A>(
that: ReadonlyRecord<K, A>
): (self: ReadonlyRecord<K, A>) => boolean
<K extends string, A>(
self: ReadonlyRecord<K, A>,
that: ReadonlyRecord<K, A>
): boolean
}
Checks whether the first record is a subrecord of the second record.
Details
Returns true when every key and value in self is also present in that.
Values are compared with Effect equality via Equal.asEquivalence().
Example (Checking subrecords)
import { Record } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(
Record.isSubrecord({ a: 1 } as Record<string, number>, { a: 1, b: 2 }),
true
)
assert.deepStrictEqual(
Record.isSubrecord({ a: 1, b: 2 }, { a: 1 } as Record<string, number>),
false
)
isSubrecord: {
<function (type parameter) K in <K extends string, A>(that: ReadonlyRecord<K, A>): (self: ReadonlyRecord<K, A>) => booleanK extends string, function (type parameter) A in <K extends string, A>(that: ReadonlyRecord<K, A>): (self: ReadonlyRecord<K, A>) => booleanA>(that: ReadonlyRecord<K, A>that: 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>(that: ReadonlyRecord<K, A>): (self: ReadonlyRecord<K, A>) => booleanK, function (type parameter) A in <K extends string, A>(that: ReadonlyRecord<K, A>): (self: ReadonlyRecord<K, A>) => booleanA>): (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>(that: ReadonlyRecord<K, A>): (self: ReadonlyRecord<K, A>) => booleanK, function (type parameter) A in <K extends string, A>(that: ReadonlyRecord<K, A>): (self: ReadonlyRecord<K, A>) => booleanA>) => boolean
<function (type parameter) K in <K extends string, A>(self: ReadonlyRecord<K, A>, that: ReadonlyRecord<K, A>): booleanK extends string, function (type parameter) A in <K extends string, A>(self: ReadonlyRecord<K, A>, that: ReadonlyRecord<K, A>): booleanA>(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>, that: ReadonlyRecord<K, A>): booleanK, function (type parameter) A in <K extends string, A>(self: ReadonlyRecord<K, A>, that: ReadonlyRecord<K, A>): booleanA>, that: ReadonlyRecord<K, A>that: 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>, that: ReadonlyRecord<K, A>): booleanK, function (type parameter) A in <K extends string, A>(self: ReadonlyRecord<K, A>, that: ReadonlyRecord<K, A>): booleanA>): boolean
} = const isSubrecordBy: <A>(
equivalence: Equivalence<A>
) => {
<K extends string>(
that: ReadonlyRecord<K, A>
): (self: ReadonlyRecord<K, A>) => boolean
<K extends string>(
self: ReadonlyRecord<K, A>,
that: ReadonlyRecord<K, A>
): boolean
}
Checks whether all the keys and values in one record are also found in another record.
Uses the provided equivalence function to compare values.
Example (Checking subrecords with a custom equivalence)
import { Equivalence, Record } from "effect"
const isSubrecord = Record.isSubrecordBy(
Equivalence.make<string>((self, that) => self.toLowerCase() === that.toLowerCase())
)
const required: Record.ReadonlyRecord<string, string> = { role: "Admin" }
const available: Record.ReadonlyRecord<string, string> = {
role: "admin",
status: "active"
}
console.log(
isSubrecord(required, available)
) // true
console.log(
isSubrecord({ role: "Admin", status: "inactive" }, available)
) // false
console.log(
isSubrecord(required, { role: "editor", status: "active" })
) // false
isSubrecordBy(import EqualEqual.asEquivalence())