/** * This module provides utility functions for working with records in TypeScript. * * @since 2.0.0 */ import type * as Combiner from "./Combiner.ts"; import type { Equivalence } from "./Equivalence.ts"; import type { TypeLambda } from "./HKT.ts"; import * as Option from "./Option.ts"; import * as Reducer from "./Reducer.ts"; import type { Result } from "./Result.ts"; import type { NoInfer } from "./Types.ts"; /** * 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 * ```ts * 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 * } * ``` * * @category models * @since 2.0.0 */ export type ReadonlyRecord = { readonly [P in K]: A; }; /** * Namespace containing utility types for working with readonly records. * These types help with type-level operations on record keys and values. * * @example * ```ts * 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" * ``` * * @category models * @since 2.0.0 */ export declare namespace ReadonlyRecord { type IsFiniteString = T extends "" ? true : [ T ] extends [`${infer Head}${infer Rest}`] ? string extends Head ? false : `${number}` extends Head ? false : Rest extends "" ? true : IsFiniteString : false; /** * Represents 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 * ```ts * 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 * ``` * * @category models * @since 2.0.0 */ type NonLiteralKey = K extends string ? IsFiniteString extends true ? string : K : symbol; /** * Represents the intersection of two key types, handling both literal and non-literal string keys. * This type is used in record operations that need to compute overlapping keys. * * @example * ```ts * import type { Record } from "effect" * * // Intersection of literal keys * type Example1 = Record.ReadonlyRecord.IntersectKeys<"a" | "b", "b" | "c"> // "b" * * // Intersection with generic string * type Example2 = Record.ReadonlyRecord.IntersectKeys // string * ``` * * @category models * @since 2.0.0 */ type IntersectKeys = [string] extends [K1 | K2] ? NonLiteralKey & NonLiteralKey : K1 & K2; } /** * Type lambda for readonly records, used in higher-kinded type operations. * This enables records to work with generic type constructors and functors. * * @example * ```ts * import type { Record } from "effect" * * // The type lambda allows records to be used as higher-kinded types * type RecordTypeLambda = Record.ReadonlyRecordTypeLambda<"key1" | "key2"> * * // This enables mapping over the type parameter * type StringRecord = RecordTypeLambda["type"] // ReadonlyRecord<"key1" | "key2", Target> * ``` * * @category type lambdas * @since 2.0.0 */ export interface ReadonlyRecordTypeLambda extends TypeLambda { readonly type: ReadonlyRecord; } /** * Creates a new, empty record. * * @example * ```ts * import { Record } from "effect" * * // Create an empty record * const emptyRecord = Record.empty() * console.log(emptyRecord) // {} * * // The type ensures type safety for future operations * const withValue = Record.set(emptyRecord, "count", 42) * console.log(withValue) // { count: 42 } * ``` * * @category constructors * @since 2.0.0 */ export declare const empty: () => Record, V>; /** * Determine if a record is empty. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.isEmptyRecord({}), true) * assert.deepStrictEqual(Record.isEmptyRecord({ a: 3 }), false) * ``` * * @category guards * @since 2.0.0 */ export declare const isEmptyRecord: (self: Record) => self is Record; /** * Determine if a record is empty. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.isEmptyReadonlyRecord({}), true) * assert.deepStrictEqual(Record.isEmptyReadonlyRecord({ a: 3 }), false) * ``` * * @category guards * @since 2.0.0 */ export declare const isEmptyReadonlyRecord: (self: ReadonlyRecord) => self is ReadonlyRecord; /** * Takes an iterable and a projection function and returns a record. * The projection function maps each value of the iterable to a tuple of a key and a value, which is then added to the resulting record. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * const input = [1, 2, 3, 4] * * assert.deepStrictEqual( * Record.fromIterableWith(input, (a) => [String(a), a * 2]), * { "1": 2, "2": 4, "3": 6, "4": 8 } * ) * ``` * * @category constructors * @since 2.0.0 */ export declare const fromIterableWith: { /** * Takes an iterable and a projection function and returns a record. * The projection function maps each value of the iterable to a tuple of a key and a value, which is then added to the resulting record. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * const input = [1, 2, 3, 4] * * assert.deepStrictEqual( * Record.fromIterableWith(input, (a) => [String(a), a * 2]), * { "1": 2, "2": 4, "3": 6, "4": 8 } * ) * ``` * * @category constructors * @since 2.0.0 */ (f: (a: A) => readonly [K, B]): (self: Iterable) => Record, B>; /** * Takes an iterable and a projection function and returns a record. * The projection function maps each value of the iterable to a tuple of a key and a value, which is then added to the resulting record. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * const input = [1, 2, 3, 4] * * assert.deepStrictEqual( * Record.fromIterableWith(input, (a) => [String(a), a * 2]), * { "1": 2, "2": 4, "3": 6, "4": 8 } * ) * ``` * * @category constructors * @since 2.0.0 */ (self: Iterable, f: (a: A) => readonly [K, B]): Record, B>; }; /** * Creates a new record from an iterable, utilizing the provided function to determine the key for each element. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * const users = [ * { id: "2", name: "name2" }, * { id: "1", name: "name1" } * ] * * assert.deepStrictEqual( * Record.fromIterableBy(users, (user) => user.id), * { * "2": { id: "2", name: "name2" }, * "1": { id: "1", name: "name1" } * } * ) * ``` * * @category constructors * @since 2.0.0 */ export declare const fromIterableBy: (items: Iterable, f: (a: A) => K) => Record, A>; /** * Builds a record from an iterable of key-value pairs. * * If there are conflicting keys when using `fromEntries`, the last occurrence of the key/value pair will overwrite the * previous ones. So the resulting record will only have the value of the last occurrence of each key. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * const input: Array<[string, number]> = [["a", 1], ["b", 2]] * * assert.deepStrictEqual(Record.fromEntries(input), { a: 1, b: 2 }) * ``` * * @since 2.0.0 * @category constructors */ export declare const fromEntries: (entries: Iterable) => Record, Entry[1]>; /** * Transforms the values of a record into an `Array` with a custom mapping function. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * const x = { a: 1, b: 2, c: 3 } * assert.deepStrictEqual(Record.collect(x, (key, n) => [key, n]), [["a", 1], [ * "b", * 2 * ], ["c", 3]]) * ``` * * @category conversions * @since 2.0.0 */ export declare const collect: { /** * Transforms the values of a record into an `Array` with a custom mapping function. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * const x = { a: 1, b: 2, c: 3 } * assert.deepStrictEqual(Record.collect(x, (key, n) => [key, n]), [["a", 1], [ * "b", * 2 * ], ["c", 3]]) * ``` * * @category conversions * @since 2.0.0 */ (f: (key: K, a: A) => B): (self: ReadonlyRecord) => Array; /** * Transforms the values of a record into an `Array` with a custom mapping function. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * const x = { a: 1, b: 2, c: 3 } * assert.deepStrictEqual(Record.collect(x, (key, n) => [key, n]), [["a", 1], [ * "b", * 2 * ], ["c", 3]]) * ``` * * @category conversions * @since 2.0.0 */ (self: ReadonlyRecord, f: (key: K, a: A) => B): Array; }; /** * Takes a record and returns an array of tuples containing its keys and values. * * @example * ```ts * 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]]) * ``` * * @category conversions * @since 2.0.0 */ export declare const toEntries: (self: ReadonlyRecord) => Array<[K, A]>; /** * Returns the number of key/value pairs in a record. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.size({ a: "a", b: 1, c: true }), 3) * ``` * * @category getters * @since 2.0.0 */ export declare const size: (self: ReadonlyRecord) => number; /** * Check if a given `key` exists in a record. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.has({ a: 1, b: 2 }, "a"), true) * assert.deepStrictEqual(Record.has(Record.empty(), "c"), false) * ``` * * @category guards * @since 2.0.0 */ export declare const has: { /** * Check if a given `key` exists in a record. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.has({ a: 1, b: 2 }, "a"), true) * assert.deepStrictEqual(Record.has(Record.empty(), "c"), false) * ``` * * @category guards * @since 2.0.0 */ (key: NoInfer): (self: ReadonlyRecord) => boolean; /** * Check if a given `key` exists in a record. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.has({ a: 1, b: 2 }, "a"), true) * assert.deepStrictEqual(Record.has(Record.empty(), "c"), false) * ``` * * @category guards * @since 2.0.0 */ (self: ReadonlyRecord, key: NoInfer): boolean; }; /** * Retrieve a value at a particular key from a record, returning it wrapped in an `Option`. * * @example * ```ts * import { Option, Record as R } from "effect" * import * as assert from "node:assert" * * const person: Record = { name: "John Doe", age: 35 } * * assert.deepStrictEqual(R.get(person, "name"), Option.some("John Doe")) * assert.deepStrictEqual(R.get(person, "email"), Option.none()) * ``` * * @category getters * @since 2.0.0 */ export declare const get: { /** * Retrieve a value at a particular key from a record, returning it wrapped in an `Option`. * * @example * ```ts * import { Option, Record as R } from "effect" * import * as assert from "node:assert" * * const person: Record = { name: "John Doe", age: 35 } * * assert.deepStrictEqual(R.get(person, "name"), Option.some("John Doe")) * assert.deepStrictEqual(R.get(person, "email"), Option.none()) * ``` * * @category getters * @since 2.0.0 */ (key: NoInfer): (self: ReadonlyRecord) => Option.Option; /** * Retrieve a value at a particular key from a record, returning it wrapped in an `Option`. * * @example * ```ts * import { Option, Record as R } from "effect" * import * as assert from "node:assert" * * const person: Record = { name: "John Doe", age: 35 } * * assert.deepStrictEqual(R.get(person, "name"), Option.some("John Doe")) * assert.deepStrictEqual(R.get(person, "email"), Option.none()) * ``` * * @category getters * @since 2.0.0 */ (self: ReadonlyRecord, key: NoInfer): Option.Option; }; /** * Apply a function to the element at the specified key, creating a new record, * or return `Option.none()` if the key doesn't exist. * * @example * ```ts * import { Record } from "effect" * * const f = (x: number) => x * 2 * * const input: Record = { a: 3 } * * Record.modify(input, "a", f) // Option.some({ a: 6 }) * Record.modify(input, "b", f) // Option.none() * ``` * * @category utils * @since 2.0.0 */ export declare const modify: { /** * Apply a function to the element at the specified key, creating a new record, * or return `Option.none()` if the key doesn't exist. * * @example * ```ts * import { Record } from "effect" * * const f = (x: number) => x * 2 * * const input: Record = { a: 3 } * * Record.modify(input, "a", f) // Option.some({ a: 6 }) * Record.modify(input, "b", f) // Option.none() * ``` * * @category utils * @since 2.0.0 */ (key: NoInfer, f: (a: A) => B): (self: ReadonlyRecord) => Option.Option>; /** * Apply a function to the element at the specified key, creating a new record, * or return `Option.none()` if the key doesn't exist. * * @example * ```ts * import { Record } from "effect" * * const f = (x: number) => x * 2 * * const input: Record = { a: 3 } * * Record.modify(input, "a", f) // Option.some({ a: 6 }) * Record.modify(input, "b", f) // Option.none() * ``` * * @category utils * @since 2.0.0 */ (self: ReadonlyRecord, key: NoInfer, f: (a: A) => B): Option.Option>; }; /** * Replaces a value in the record with the new value passed as parameter. * * @example * ```ts * import { Record } from "effect" * * Record.replace({ a: 1, b: 2, c: 3 }, "a", 10) // Option.some({ a: 10, b: 2, c: 3 }) * Record.replace(Record.empty(), "a", 10) // Option.none() * ``` * * @category utils * @since 2.0.0 */ export declare const replace: { /** * Replaces a value in the record with the new value passed as parameter. * * @example * ```ts * import { Record } from "effect" * * Record.replace({ a: 1, b: 2, c: 3 }, "a", 10) // Option.some({ a: 10, b: 2, c: 3 }) * Record.replace(Record.empty(), "a", 10) // Option.none() * ``` * * @category utils * @since 2.0.0 */ (key: NoInfer, b: B): (self: ReadonlyRecord) => Option.Option>; /** * Replaces a value in the record with the new value passed as parameter. * * @example * ```ts * import { Record } from "effect" * * Record.replace({ a: 1, b: 2, c: 3 }, "a", 10) // Option.some({ a: 10, b: 2, c: 3 }) * Record.replace(Record.empty(), "a", 10) // Option.none() * ``` * * @category utils * @since 2.0.0 */ (self: ReadonlyRecord, key: NoInfer, b: B): Option.Option>; }; /** * If the given key exists in the record, returns a new record with the key removed. * If the key does not exist, returns a shallow copy of the original record. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.remove({ a: 1, b: 2 }, "a"), { b: 2 }) * ``` * * @category utils * @since 2.0.0 */ export declare const remove: { /** * If the given key exists in the record, returns a new record with the key removed. * If the key does not exist, returns a shallow copy of the original record. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.remove({ a: 1, b: 2 }, "a"), { b: 2 }) * ``` * * @category utils * @since 2.0.0 */ (key: X): (self: ReadonlyRecord) => Record, A>; /** * If the given key exists in the record, returns a new record with the key removed. * If the key does not exist, returns a shallow copy of the original record. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.remove({ a: 1, b: 2 }, "a"), { b: 2 }) * ``` * * @category utils * @since 2.0.0 */ (self: ReadonlyRecord, key: X): Record, A>; }; /** * Retrieves the value of the property with the given `key` from a record and returns an `Option` * of a tuple with the value and the record with the removed property. * If the key is not present, returns `Option.none()`. * * @example * ```ts * import { Record } from "effect" * * const input: Record = { a: 1, b: 2 } * * Record.pop(input, "a") // Option.some([1, { b: 2 }]) * Record.pop(input, "c") // Option.none() * ``` * * @category utils * @since 2.0.0 */ export declare const pop: { /** * Retrieves the value of the property with the given `key` from a record and returns an `Option` * of a tuple with the value and the record with the removed property. * If the key is not present, returns `Option.none()`. * * @example * ```ts * import { Record } from "effect" * * const input: Record = { a: 1, b: 2 } * * Record.pop(input, "a") // Option.some([1, { b: 2 }]) * Record.pop(input, "c") // Option.none() * ``` * * @category utils * @since 2.0.0 */ (key: X): (self: ReadonlyRecord) => Option.Option<[A, Record, A>]>; /** * Retrieves the value of the property with the given `key` from a record and returns an `Option` * of a tuple with the value and the record with the removed property. * If the key is not present, returns `Option.none()`. * * @example * ```ts * import { Record } from "effect" * * const input: Record = { a: 1, b: 2 } * * Record.pop(input, "a") // Option.some([1, { b: 2 }]) * Record.pop(input, "c") // Option.none() * ``` * * @category utils * @since 2.0.0 */ (self: ReadonlyRecord, key: X): Option.Option<[A, Record, A>]>; }; /** * Maps a record into another record by applying a transformation function to each of its values. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * const f = (n: number) => `-${n}` * * assert.deepStrictEqual(Record.map({ a: 3, b: 5 }, f), { a: "-3", b: "-5" }) * * const g = (n: number, key: string) => `${key.toUpperCase()}-${n}` * * assert.deepStrictEqual(Record.map({ a: 3, b: 5 }, g), { a: "A-3", b: "B-5" }) * ``` * * @category mapping * @since 2.0.0 */ export declare const map: { /** * Maps a record into another record by applying a transformation function to each of its values. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * const f = (n: number) => `-${n}` * * assert.deepStrictEqual(Record.map({ a: 3, b: 5 }, f), { a: "-3", b: "-5" }) * * const g = (n: number, key: string) => `${key.toUpperCase()}-${n}` * * assert.deepStrictEqual(Record.map({ a: 3, b: 5 }, g), { a: "A-3", b: "B-5" }) * ``` * * @category mapping * @since 2.0.0 */ (f: (a: A, key: NoInfer) => B): (self: ReadonlyRecord) => Record; /** * Maps a record into another record by applying a transformation function to each of its values. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * const f = (n: number) => `-${n}` * * assert.deepStrictEqual(Record.map({ a: 3, b: 5 }, f), { a: "-3", b: "-5" }) * * const g = (n: number, key: string) => `${key.toUpperCase()}-${n}` * * assert.deepStrictEqual(Record.map({ a: 3, b: 5 }, g), { a: "A-3", b: "B-5" }) * ``` * * @category mapping * @since 2.0.0 */ (self: ReadonlyRecord, f: (a: A, key: NoInfer) => B): Record; }; /** * Maps the keys of a `ReadonlyRecord` while preserving the corresponding values. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.mapKeys({ a: 3, b: 5 }, (key) => key.toUpperCase()), * { A: 3, B: 5 } * ) * ``` * * @category mapping * @since 2.0.0 */ export declare const mapKeys: { /** * Maps the keys of a `ReadonlyRecord` while preserving the corresponding values. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.mapKeys({ a: 3, b: 5 }, (key) => key.toUpperCase()), * { A: 3, B: 5 } * ) * ``` * * @category mapping * @since 2.0.0 */ (f: (key: K, a: A) => K2): (self: ReadonlyRecord) => Record; /** * Maps the keys of a `ReadonlyRecord` while preserving the corresponding values. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.mapKeys({ a: 3, b: 5 }, (key) => key.toUpperCase()), * { A: 3, B: 5 } * ) * ``` * * @category mapping * @since 2.0.0 */ (self: ReadonlyRecord, f: (key: K, a: A) => K2): Record; }; /** * Maps entries of a `ReadonlyRecord` using the provided function, allowing modification of both keys and corresponding values. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.mapEntries({ a: 3, b: 5 }, (a, key) => [key.toUpperCase(), a + 1]), * { A: 4, B: 6 } * ) * ``` * * @category mapping * @since 2.0.0 */ export declare const mapEntries: { /** * Maps entries of a `ReadonlyRecord` using the provided function, allowing modification of both keys and corresponding values. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.mapEntries({ a: 3, b: 5 }, (a, key) => [key.toUpperCase(), a + 1]), * { A: 4, B: 6 } * ) * ``` * * @category mapping * @since 2.0.0 */ (f: (a: A, key: K) => readonly [K2, B]): (self: ReadonlyRecord) => Record; /** * Maps entries of a `ReadonlyRecord` using the provided function, allowing modification of both keys and corresponding values. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.mapEntries({ a: 3, b: 5 }, (a, key) => [key.toUpperCase(), a + 1]), * { A: 4, B: 6 } * ) * ``` * * @category mapping * @since 2.0.0 */ (self: ReadonlyRecord, f: (a: A, key: K) => [K2, B]): Record; }; /** * Transforms a record by applying the function `f` to each key and value in the original record. * If the function succeeds, the key-value pair is included in the output record. * * @example * ```ts * import { Record, Result } from "effect" * import * as assert from "node:assert" * * const x = { a: 1, b: 2, c: 3 } * const f = (a: number, key: string) => a > 2 ? Result.succeed(a * 2) : Result.failVoid * assert.deepStrictEqual(Record.filterMap(x, f), { c: 6 }) * ``` * * @category filtering * @since 2.0.0 */ export declare const filterMap: { /** * Transforms a record by applying the function `f` to each key and value in the original record. * If the function succeeds, the key-value pair is included in the output record. * * @example * ```ts * import { Record, Result } from "effect" * import * as assert from "node:assert" * * const x = { a: 1, b: 2, c: 3 } * const f = (a: number, key: string) => a > 2 ? Result.succeed(a * 2) : Result.failVoid * assert.deepStrictEqual(Record.filterMap(x, f), { c: 6 }) * ``` * * @category filtering * @since 2.0.0 */ (f: (input: A, key: K) => Result): (self: ReadonlyRecord) => Record, B>; /** * Transforms a record by applying the function `f` to each key and value in the original record. * If the function succeeds, the key-value pair is included in the output record. * * @example * ```ts * import { Record, Result } from "effect" * import * as assert from "node:assert" * * const x = { a: 1, b: 2, c: 3 } * const f = (a: number, key: string) => a > 2 ? Result.succeed(a * 2) : Result.failVoid * assert.deepStrictEqual(Record.filterMap(x, f), { c: 6 }) * ``` * * @category filtering * @since 2.0.0 */ (self: ReadonlyRecord, f: (input: A, key: K) => Result): Record, B>; }; /** * Selects properties from a record whose values match the given predicate. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * const x = { a: 1, b: 2, c: 3, d: 4 } * assert.deepStrictEqual(Record.filter(x, (n) => n > 2), { c: 3, d: 4 }) * ``` * * @category filtering * @since 2.0.0 */ export declare const filter: { /** * Selects properties from a record whose values match the given predicate. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * const x = { a: 1, b: 2, c: 3, d: 4 } * assert.deepStrictEqual(Record.filter(x, (n) => n > 2), { c: 3, d: 4 }) * ``` * * @category filtering * @since 2.0.0 */ (refinement: (a: NoInfer, key: K) => a is B): (self: ReadonlyRecord) => Record, B>; /** * Selects properties from a record whose values match the given predicate. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * const x = { a: 1, b: 2, c: 3, d: 4 } * assert.deepStrictEqual(Record.filter(x, (n) => n > 2), { c: 3, d: 4 }) * ``` * * @category filtering * @since 2.0.0 */ (predicate: (A: NoInfer, key: K) => boolean): (self: ReadonlyRecord) => Record, A>; /** * Selects properties from a record whose values match the given predicate. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * const x = { a: 1, b: 2, c: 3, d: 4 } * assert.deepStrictEqual(Record.filter(x, (n) => n > 2), { c: 3, d: 4 }) * ``` * * @category filtering * @since 2.0.0 */ (self: ReadonlyRecord, refinement: (a: A, key: K) => a is B): Record, B>; /** * Selects properties from a record whose values match the given predicate. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * const x = { a: 1, b: 2, c: 3, d: 4 } * assert.deepStrictEqual(Record.filter(x, (n) => n > 2), { c: 3, d: 4 }) * ``` * * @category filtering * @since 2.0.0 */ (self: ReadonlyRecord, predicate: (a: A, key: K) => boolean): Record, A>; }; /** * Given a record with `Option` values, returns a new record containing only the `Some` values, preserving the original keys. * * @example * ```ts * 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 } * ) * ``` * * @category filtering * @since 2.0.0 */ export declare const getSomes: (self: ReadonlyRecord>) => Record, A>; /** * Given a record with `Result` values, returns a new record containing only the `Err` values, preserving the original keys. * * @example * ```ts * import { Record, Result } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.getFailures({ * a: Result.succeed(1), * b: Result.fail("err"), * c: Result.succeed(2) * }), * { b: "err" } * ) * ``` * * @category filtering * @since 2.0.0 */ export declare const getFailures: (self: ReadonlyRecord>) => Record, E>; /** * Given a record with `Result` values, returns a new record containing only the `Ok` values, preserving the original keys. * * @example * ```ts * import { Record, Result } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.getSuccesses({ * a: Result.succeed(1), * b: Result.fail("err"), * c: Result.succeed(2) * }), * { a: 1, c: 2 } * ) * ``` * * @category filtering * @since 2.0.0 */ export declare const getSuccesses: (self: ReadonlyRecord>) => Record; /** * Partitions the elements of a record into two groups: those that match a filter, and those that don't. * * @example * ```ts * import { Record, Result } from "effect" * import * as assert from "node:assert" * * const x = { a: 1, b: 2, c: 3 } * const f = (n: number) => (n % 2 === 0 ? Result.succeed(n) : Result.fail(n)) * assert.deepStrictEqual(Record.partition(x, f), [{ a: 1, c: 3 }, { b: 2 }]) * ``` * * @category filtering * @since 2.0.0 */ export declare const partition: { /** * Partitions the elements of a record into two groups: those that match a filter, and those that don't. * * @example * ```ts * import { Record, Result } from "effect" * import * as assert from "node:assert" * * const x = { a: 1, b: 2, c: 3 } * const f = (n: number) => (n % 2 === 0 ? Result.succeed(n) : Result.fail(n)) * assert.deepStrictEqual(Record.partition(x, f), [{ a: 1, c: 3 }, { b: 2 }]) * ``` * * @category filtering * @since 2.0.0 */ (f: (input: A, key: K) => Result): (self: ReadonlyRecord) => [left: Record, B>, right: Record, C>]; /** * Partitions the elements of a record into two groups: those that match a filter, and those that don't. * * @example * ```ts * import { Record, Result } from "effect" * import * as assert from "node:assert" * * const x = { a: 1, b: 2, c: 3 } * const f = (n: number) => (n % 2 === 0 ? Result.succeed(n) : Result.fail(n)) * assert.deepStrictEqual(Record.partition(x, f), [{ a: 1, c: 3 }, { b: 2 }]) * ``` * * @category filtering * @since 2.0.0 */ (self: ReadonlyRecord, f: (input: A, key: K) => Result): [left: Record, B>, right: Record, C>]; }; /** * Partitions a record of `Result` values into two separate records, * one with the `Err` values and one with the `Ok` values. * * @example * ```ts * import { Record, Result } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.separate({ a: Result.fail("e"), b: Result.succeed(1) }), * [{ a: "e" }, { b: 1 }] * ) * ``` * * @category filtering * @since 2.0.0 */ export declare const separate: (self: ReadonlyRecord>) => [Record, A>, Record, B>]; /** * Retrieve the keys of a given record as an array. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.keys({ a: 1, b: 2, c: 3 }), ["a", "b", "c"]) * ``` * * @category getters * @since 2.0.0 */ export declare const keys: (self: ReadonlyRecord) => Array; /** * Retrieve the values of a given record as an array. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.values({ a: 1, b: 2, c: 3 }), [1, 2, 3]) * ``` * * @category getters * @since 2.0.0 */ export declare const values: (self: ReadonlyRecord) => Array; /** * Add a new key-value pair or update an existing key's value in a record. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.set("a", 5)({ a: 1, b: 2 }), { a: 5, b: 2 }) * assert.deepStrictEqual(Record.set("c", 5)({ a: 1, b: 2 }), { a: 1, b: 2, c: 5 }) * ``` * * @category utils * @since 2.0.0 */ export declare const set: { /** * Add a new key-value pair or update an existing key's value in a record. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.set("a", 5)({ a: 1, b: 2 }), { a: 5, b: 2 }) * assert.deepStrictEqual(Record.set("c", 5)({ a: 1, b: 2 }), { a: 1, b: 2, c: 5 }) * ``` * * @category utils * @since 2.0.0 */ (key: K1, value: B): (self: ReadonlyRecord) => Record; /** * Add a new key-value pair or update an existing key's value in a record. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.set("a", 5)({ a: 1, b: 2 }), { a: 5, b: 2 }) * assert.deepStrictEqual(Record.set("c", 5)({ a: 1, b: 2 }), { a: 1, b: 2, c: 5 }) * ``` * * @category utils * @since 2.0.0 */ (self: ReadonlyRecord, key: K1, value: B): Record; }; /** * Check if all the keys and values in one record are also found in another record. * Uses the provided equivalence function to compare values. * * @example * ```ts * import { Equal, Record } from "effect" * import * as assert from "node:assert" * * const isSubrecord = Record.isSubrecordBy(Equal.asEquivalence()) * * assert.deepStrictEqual( * Record.isSubrecord({ a: 1 } as Record, { a: 1, b: 2 }), * true * ) * assert.deepStrictEqual( * Record.isSubrecord({ a: 1, b: 2 }, { a: 1 } as Record), * false * ) * ``` * * @category predicates * @since 2.0.0 */ export declare const isSubrecordBy: (equivalence: Equivalence) => { (that: ReadonlyRecord): (self: ReadonlyRecord) => boolean; (self: ReadonlyRecord, that: ReadonlyRecord): boolean; }; /** * Check if one record is a subrecord of another, meaning it contains all the keys and values found in the second record. * This comparison uses default equality checks (`Equal.equivalence()`). * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.isSubrecord({ a: 1 } as Record, { a: 1, b: 2 }), * true * ) * assert.deepStrictEqual( * Record.isSubrecord({ a: 1, b: 2 }, { a: 1 } as Record), * false * ) * ``` * * @category predicates * @since 2.0.0 */ export declare const isSubrecord: { /** * Check if one record is a subrecord of another, meaning it contains all the keys and values found in the second record. * This comparison uses default equality checks (`Equal.equivalence()`). * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.isSubrecord({ a: 1 } as Record, { a: 1, b: 2 }), * true * ) * assert.deepStrictEqual( * Record.isSubrecord({ a: 1, b: 2 }, { a: 1 } as Record), * false * ) * ``` * * @category predicates * @since 2.0.0 */ (that: ReadonlyRecord): (self: ReadonlyRecord) => boolean; /** * Check if one record is a subrecord of another, meaning it contains all the keys and values found in the second record. * This comparison uses default equality checks (`Equal.equivalence()`). * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.isSubrecord({ a: 1 } as Record, { a: 1, b: 2 }), * true * ) * assert.deepStrictEqual( * Record.isSubrecord({ a: 1, b: 2 }, { a: 1 } as Record), * false * ) * ``` * * @category predicates * @since 2.0.0 */ (self: ReadonlyRecord, that: ReadonlyRecord): boolean; }; /** * Reduce a record to a single value by combining its entries with a specified function. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.reduce({ a: 1, b: 2, c: 3 }, 0, (acc, value, key) => acc + value), * 6 * ) * ``` * * @category folding * @since 2.0.0 */ export declare const reduce: { /** * Reduce a record to a single value by combining its entries with a specified function. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.reduce({ a: 1, b: 2, c: 3 }, 0, (acc, value, key) => acc + value), * 6 * ) * ``` * * @category folding * @since 2.0.0 */ (zero: Z, f: (accumulator: Z, value: V, key: K) => Z): (self: ReadonlyRecord) => Z; /** * Reduce a record to a single value by combining its entries with a specified function. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.reduce({ a: 1, b: 2, c: 3 }, 0, (acc, value, key) => acc + value), * 6 * ) * ``` * * @category folding * @since 2.0.0 */ (self: ReadonlyRecord, zero: Z, f: (accumulator: Z, value: V, key: K) => Z): Z; }; /** * Check if all entries in a record meet a specific condition. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.every({ a: 1, b: 2 }, (n) => n > 0), true) * assert.deepStrictEqual(Record.every({ a: 1, b: -1 }, (n) => n > 0), false) * ``` * * @category predicates * @since 2.0.0 */ export declare const every: { /** * Check if all entries in a record meet a specific condition. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.every({ a: 1, b: 2 }, (n) => n > 0), true) * assert.deepStrictEqual(Record.every({ a: 1, b: -1 }, (n) => n > 0), false) * ``` * * @category predicates * @since 2.0.0 */ (refinement: (value: A, key: K) => value is B): (self: ReadonlyRecord) => self is ReadonlyRecord; /** * Check if all entries in a record meet a specific condition. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.every({ a: 1, b: 2 }, (n) => n > 0), true) * assert.deepStrictEqual(Record.every({ a: 1, b: -1 }, (n) => n > 0), false) * ``` * * @category predicates * @since 2.0.0 */ (predicate: (value: A, key: K) => boolean): (self: ReadonlyRecord) => boolean; /** * Check if all entries in a record meet a specific condition. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.every({ a: 1, b: 2 }, (n) => n > 0), true) * assert.deepStrictEqual(Record.every({ a: 1, b: -1 }, (n) => n > 0), false) * ``` * * @category predicates * @since 2.0.0 */ (self: ReadonlyRecord, refinement: (value: A, key: K) => value is B): self is ReadonlyRecord; /** * Check if all entries in a record meet a specific condition. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.every({ a: 1, b: 2 }, (n) => n > 0), true) * assert.deepStrictEqual(Record.every({ a: 1, b: -1 }, (n) => n > 0), false) * ``` * * @category predicates * @since 2.0.0 */ (self: ReadonlyRecord, predicate: (value: A, key: K) => boolean): boolean; }; /** * Check if any entry in a record meets a specific condition. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.some({ a: 1, b: 2 }, (n) => n > 1), true) * assert.deepStrictEqual(Record.some({ a: 1, b: 2 }, (n) => n > 2), false) * ``` * * @category predicates * @since 2.0.0 */ export declare const some: { /** * Check if any entry in a record meets a specific condition. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.some({ a: 1, b: 2 }, (n) => n > 1), true) * assert.deepStrictEqual(Record.some({ a: 1, b: 2 }, (n) => n > 2), false) * ``` * * @category predicates * @since 2.0.0 */ (predicate: (value: A, key: K) => boolean): (self: ReadonlyRecord) => boolean; /** * Check if any entry in a record meets a specific condition. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.some({ a: 1, b: 2 }, (n) => n > 1), true) * assert.deepStrictEqual(Record.some({ a: 1, b: 2 }, (n) => n > 2), false) * ``` * * @category predicates * @since 2.0.0 */ (self: ReadonlyRecord, predicate: (value: A, key: K) => boolean): boolean; }; /** * Merge two records, preserving entries that exist in either of the records. * For keys that exist in both records, the provided combine function is used to merge the values. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.union({ a: 1, b: 2 }, { b: 3, c: 4 }, (a, b) => a + b), * { a: 1, b: 5, c: 4 } * ) * ``` * * @category combining * @since 2.0.0 */ export declare const union: { /** * Merge two records, preserving entries that exist in either of the records. * For keys that exist in both records, the provided combine function is used to merge the values. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.union({ a: 1, b: 2 }, { b: 3, c: 4 }, (a, b) => a + b), * { a: 1, b: 5, c: 4 } * ) * ``` * * @category combining * @since 2.0.0 */ (that: ReadonlyRecord, combine: (selfValue: A, thatValue: B) => C): (self: ReadonlyRecord) => Record; /** * Merge two records, preserving entries that exist in either of the records. * For keys that exist in both records, the provided combine function is used to merge the values. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.union({ a: 1, b: 2 }, { b: 3, c: 4 }, (a, b) => a + b), * { a: 1, b: 5, c: 4 } * ) * ``` * * @category combining * @since 2.0.0 */ (self: ReadonlyRecord, that: ReadonlyRecord, combine: (selfValue: A, thatValue: B) => C): Record; }; /** * Merge two records, retaining only the entries that exist in both records. * For intersecting keys, the provided combine function is used to merge the values. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.intersection({ a: 1, b: 2 }, { b: 3, c: 4 }, (a, b) => a + b), * { b: 5 } * ) * ``` * * @category combining * @since 2.0.0 */ export declare const intersection: { /** * Merge two records, retaining only the entries that exist in both records. * For intersecting keys, the provided combine function is used to merge the values. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.intersection({ a: 1, b: 2 }, { b: 3, c: 4 }, (a, b) => a + b), * { b: 5 } * ) * ``` * * @category combining * @since 2.0.0 */ (that: ReadonlyRecord, combine: (selfValue: A, thatValue: B) => C): (self: ReadonlyRecord) => Record, C>; /** * Merge two records, retaining only the entries that exist in both records. * For intersecting keys, the provided combine function is used to merge the values. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.intersection({ a: 1, b: 2 }, { b: 3, c: 4 }, (a, b) => a + b), * { b: 5 } * ) * ``` * * @category combining * @since 2.0.0 */ (self: ReadonlyRecord, that: ReadonlyRecord, combine: (selfValue: A, thatValue: B) => C): Record, C>; }; /** * Merge two records, preserving only the entries that are unique to each record. * Keys that exist in both records are excluded from the result. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.difference({ a: 1, b: 2 }, { b: 3, c: 4 }), * { a: 1, c: 4 } * ) * ``` * * @category combining * @since 2.0.0 */ export declare const difference: { /** * Merge two records, preserving only the entries that are unique to each record. * Keys that exist in both records are excluded from the result. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.difference({ a: 1, b: 2 }, { b: 3, c: 4 }), * { a: 1, c: 4 } * ) * ``` * * @category combining * @since 2.0.0 */ (that: ReadonlyRecord): (self: ReadonlyRecord) => Record; /** * Merge two records, preserving only the entries that are unique to each record. * Keys that exist in both records are excluded from the result. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual( * Record.difference({ a: 1, b: 2 }, { b: 3, c: 4 }), * { a: 1, c: 4 } * ) * ``` * * @category combining * @since 2.0.0 */ (self: ReadonlyRecord, that: ReadonlyRecord): Record; }; /** * Create an `Equivalence` for records using the provided `Equivalence` for values. * Two records are considered equivalent if they have the same keys and their corresponding values are equivalent. * * @example * ```ts * import { Equal, Record } from "effect" * import * as assert from "node:assert" * * const recordEquivalence = Record.makeEquivalence(Equal.asEquivalence()) * * assert.deepStrictEqual(recordEquivalence({ a: 1, b: 2 }, { a: 1, b: 2 }), true) * assert.deepStrictEqual(recordEquivalence({ a: 1, b: 2 }, { a: 1, b: 3 }), false) * ``` * * @category instances * @since 2.0.0 */ export declare const makeEquivalence: (equivalence: Equivalence) => Equivalence>; /** * Create a non-empty record from a single element. * * @example * ```ts * import { Record } from "effect" * import * as assert from "node:assert" * * assert.deepStrictEqual(Record.singleton("a", 1), { a: 1 }) * ``` * * @category constructors * @since 2.0.0 */ export declare const singleton: (key: K, value: A) => Record; /** * A `Reducer` for combining `Record`s using union. * * Values for keys that exist in both records are combined using the provided `Combiner`. * * @since 4.0.0 */ export declare function makeReducerUnion(combiner: Combiner.Combiner): Reducer.Reducer>; /** * A `Reducer` for combining `Record`s using intersection. * * Values are combined using the provided `Combiner`. * * @since 4.0.0 */ export declare function makeReducerIntersection(combiner: Combiner.Combiner): Reducer.Reducer>; /** * Returns the first entry that satisfies the specified * predicate, or `None` if no such entry exists. * * @example * ```ts * import { Record } from "effect" * * const record = { a: 1, b: 2, c: 3 } * const result = Record.findFirst( * record, * (value, key) => value > 1 && key !== "b" * ) * console.log(result) // Option.Some(["c", 3]) * ``` * * @category elements * @since 3.14.0 */ export declare const findFirst: { /** * Returns the first entry that satisfies the specified * predicate, or `None` if no such entry exists. * * @example * ```ts * import { Record } from "effect" * * const record = { a: 1, b: 2, c: 3 } * const result = Record.findFirst( * record, * (value, key) => value > 1 && key !== "b" * ) * console.log(result) // Option.Some(["c", 3]) * ``` * * @category elements * @since 3.14.0 */ (refinement: (value: NoInfer, key: NoInfer) => value is V2): (self: ReadonlyRecord) => Option.Option<[K, V2]>; /** * Returns the first entry that satisfies the specified * predicate, or `None` if no such entry exists. * * @example * ```ts * import { Record } from "effect" * * const record = { a: 1, b: 2, c: 3 } * const result = Record.findFirst( * record, * (value, key) => value > 1 && key !== "b" * ) * console.log(result) // Option.Some(["c", 3]) * ``` * * @category elements * @since 3.14.0 */ (predicate: (value: NoInfer, key: NoInfer) => boolean): (self: ReadonlyRecord) => Option.Option<[K, V]>; /** * Returns the first entry that satisfies the specified * predicate, or `None` if no such entry exists. * * @example * ```ts * import { Record } from "effect" * * const record = { a: 1, b: 2, c: 3 } * const result = Record.findFirst( * record, * (value, key) => value > 1 && key !== "b" * ) * console.log(result) // Option.Some(["c", 3]) * ``` * * @category elements * @since 3.14.0 */ (self: ReadonlyRecord, refinement: (value: NoInfer, key: NoInfer) => value is V2): Option.Option<[K, V2]>; /** * Returns the first entry that satisfies the specified * predicate, or `None` if no such entry exists. * * @example * ```ts * import { Record } from "effect" * * const record = { a: 1, b: 2, c: 3 } * const result = Record.findFirst( * record, * (value, key) => value > 1 && key !== "b" * ) * console.log(result) // Option.Some(["c", 3]) * ``` * * @category elements * @since 3.14.0 */ (self: ReadonlyRecord, predicate: (value: NoInfer, key: NoInfer) => boolean): Option.Option<[K, V]>; }; //# sourceMappingURL=Record.d.ts.map