//#region src/index.d.ts /** * alias for `undefined`. */ type unit = undefined; /** * alias for `undefined`. */ declare const unit: undefined; /** * Simplifies a complex type intersection into a flat object type for better readability * in IDE tooltips and error messages. */ type Pretty = { [P in keyof T]: T[P] } & {}; /** * An extension of Extract for type predicates which falls back to the base * in order to narrow the `unknown` case. * * @example * function isMyType(data: T | MyType): data is NarrowedTo { ... } */ type NarrowedTo = Extract extends never ? Base : 0 extends 1 & NoInfer ? Base : Extract; /** * A function that takes a guard function as predicate and returns a guard that negates it. * * @param predicate - The guard function to negate. * @returns A guard function that negates the given predicate. */ declare function not(predicate: (data: T) => data is S): (data: T) => data is Exclude; declare function not(predicate: (data: T) => boolean): (data: T) => boolean; /** * A function that takes two guard functions as predicates and returns a guard that checks if either of them is true. * * @param a - The first guard function. * @param b - The second guard function. * @returns A guard function that checks if either predicate is true. */ declare function or(a: (data: T) => data is S, b: (data: T) => data is U): (data: T) => data is S | U; declare function or(a: (data: T) => data is S, b: (data: T) => boolean): (data: T) => data is S; declare function or(a: (data: T) => boolean, b: (data: T) => data is U): (data: T) => data is U; declare function or(a: (data: T) => boolean, b: (data: T) => boolean): (data: T) => boolean; /** * A function that checks if the passed parameter is an Array and narrows its type accordingly. * * @param data - The variable to check. * @returns True if the passed input is an Array, false otherwise. */ declare function isArray(data: ArrayLike | T): data is NarrowedTo>; /** * Checks if the given parameter is of type `"object"` via `typeof`, excluding `null`. * * @param data - The variable to be checked for being an object type. * @returns The input type, narrowed to only objects. */ declare function isObject(data: T | object): data is NarrowedTo; /** * A function that checks if the passed parameter is truthy and narrows its type accordingly. * * @param data - The variable to check. * @returns True if the passed input is truthy, false otherwise. */ declare function isTruthy(data: T): data is Exclude; /** * Tests if a value is a `function`. * * @param input - The value to test. * @returns `true` if the input is a function, `false` otherwise. * @example * ```ts * import * as assert from "node:assert" * import { isFunction } from "effect/Predicate" * * assert.deepStrictEqual(isFunction(isFunction), true) * assert.deepStrictEqual(isFunction("function"), false) * ``` * * @since 1.0.0 */ declare const isFunction: (input: unknown) => input is Function; /** * Returns its argument. * * @param x - The value to return. * @returns The input value unchanged. */ declare function identity(x: T): T; /** * Creates a function that can be used in a data-last (aka `pipe`able) or * data-first style. * * The first parameter to `dual` is either the arity of the uncurried function * or a predicate that determines if the function is being used in a data-first * or data-last style. * * Using the arity is the most common use case, but there are some cases where * you may want to use a predicate. For example, if you have a function that * takes an optional argument, you can use a predicate to determine if the * function is being used in a data-first or data-last style. * * You can pass either the arity of the uncurried function or a predicate * which determines if the function is being used in a data-first or * data-last style. * * **Example** (Using arity to determine data-first or data-last style) * * ```ts * import { dual, pipe } from "effect/Function" * * const sum = dual< * (that: number) => (self: number) => number, * (self: number, that: number) => number * >(2, (self, that) => self + that) * * console.log(sum(2, 3)) // 5 * console.log(pipe(2, sum(3))) // 5 * ``` * * **Example** (Using call signatures to define the overloads) * * ```ts * import { dual, pipe } from "effect/Function" * * const sum: { * (that: number): (self: number) => number * (self: number, that: number): number * } = dual(2, (self: number, that: number): number => self + that) * * console.log(sum(2, 3)) // 5 * console.log(pipe(2, sum(3))) // 5 * ``` * * **Example** (Using a predicate to determine data-first or data-last style) * * ```ts * import { dual, pipe } from "effect/Function" * * const sum = dual< * (that: number) => (self: number) => number, * (self: number, that: number) => number * >( * (args) => args.length === 2, * (self, that) => self + that * ) * * console.log(sum(2, 3)) // 5 * console.log(pipe(2, sum(3))) // 5 * ``` * * @param arity - The arity of the uncurried function or a predicate that determines if the function is being used in a data-first or data-last style. * @param body - The function to be curried. * @since 1.0.0 */ declare const dual: { ) => any, DataFirst extends (...args: Array) => any>(arity: Parameters["length"], body: DataFirst): DataLast & DataFirst; ) => any, DataFirst extends (...args: Array) => any>(isDataFirst: (args: IArguments) => boolean, body: DataFirst): DataLast & DataFirst; }; /** * Apply a function to a given value. * * @param a - The value to apply. * @returns A function that takes a function and applies it to the given value. * @example * ```ts * import * as assert from "node:assert" * import { pipe, apply } from "effect/Function" * import { length } from "effect/String" * * assert.deepStrictEqual(pipe(length, apply("hello")), 5) * ``` * * @since 1.0.0 */ declare const apply: (a: A) => (self: (a: A) => B) => B; /** * Returns a function that always returns the same value. * * @param x - The value to return. * @returns A function that always returns the given value. */ declare function constant(x: T): () => T; /** * Do nothing and return `void`. */ declare function constVoid(): void; /** * Do nothing and return `null`. * * @returns null */ declare function constNull(): null; /** * Do nothing and return `true`. * * @returns true */ declare function constTrue(): true; /** * Do nothing and return `false`. * * @returns false */ declare function constFalse(): false; /** * Reverses the order of arguments for a curried function. * * @param f - The function to flip. * @returns A new function with the argument order reversed. * @example * ```ts * import * as assert from "node:assert" * import { flip } from "effect/Function" * * const f = (a: number) => (b: string) => a - b.length * * assert.deepStrictEqual(flip(f)('aaa')(2), -1) * ``` * * @since 1.0.0 */ declare const flip: , B extends Array, C>(f: (...a: A) => (...b: B) => C) => (...b: B) => (...a: A) => C; /** * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`. * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`. * * @param self - The first function to apply (or the composed function in data-last style). * @param bc - The second function to apply. * @returns A composed function that applies both functions in sequence. * @example * ```ts * import * as assert from "node:assert" * import { compose } from "effect/Function" * * const increment = (n: number) => n + 1; * const square = (n: number) => n * n; * * assert.strictEqual(compose(increment, square)(2), 9); * ``` * * @since 1.0.0 */ declare const compose: { (bc: (b: B) => C): (self: (a: A) => B) => (a: A) => C; (self: (a: A) => B, bc: (b: B) => C): (a: A) => C; }; /** * The `absurd` function is a stub for cases where a value of type `never` is encountered in your code, * meaning that it should be impossible for this code to be executed. * * This function is particularly useful when it's necessary to specify that certain cases are impossible. * * @param _ - The value of type `never` that is passed to the function. * @since 1.0.0 */ declare const absurd: (_: never) => A; /** * Creates a tupled version of this function: instead of `n` arguments, it accepts a single tuple argument. * * @param f - The function to be converted. * @returns A new function that accepts a single tuple argument. * @example * ```ts * import * as assert from "node:assert" * import { tupled } from "effect/Function" * * const sumTupled = tupled((x: number, y: number): number => x + y) * * assert.deepStrictEqual(sumTupled([1, 2]), 3) * ``` * * @since 1.0.0 */ declare const tupled: , B>(f: (...a: A) => B) => (a: A) => B; /** * Inverse function of `tupled`. * * @param f - The function to be converted. * @returns A new function that accepts spread arguments instead of a tuple. * @example * ```ts * import * as assert from "node:assert" * import { untupled } from "effect/Function" * * const getFirst = untupled((tuple: [A, B]): A => tuple[0]) * * assert.deepStrictEqual(getFirst(1, 2), 1) * ``` * * @since 1.0.0 */ declare const untupled: , B>(f: (a: A) => B) => (...a: A) => B; /** * Applies a pipeline of functions to a value, passing the result of each function * to the next one in sequence. * * @param self - The value to pipe. * @param args - The functions to apply. * @returns The result of applying all functions in sequence. * @since 1.0.0 */ declare const pipeArguments: (self: A, args: IArguments) => unknown; /** * Pipes the value of an expression into a pipeline of functions. * * **Details** * * The `pipe` function is a utility that allows us to compose functions in a * readable and sequential manner. It takes the output of one function and * passes it as the input to the next function in the pipeline. This enables us * to build complex transformations by chaining multiple functions together. * * ```ts skip-type-checking * import { pipe } from "effect" * * const result = pipe(input, func1, func2, ..., funcN) * ``` * * In this syntax, `input` is the initial value, and `func1`, `func2`, ..., * `funcN` are the functions to be applied in sequence. The result of each * function becomes the input for the next function, and the final result is * returned. * * Here's an illustration of how `pipe` works: * * ``` * ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌────────┐ * │ input │───►│ func1 │───►│ func2 │───►│ ... │───►│ funcN │───►│ result │ * └───────┘ └───────┘ └───────┘ └───────┘ └───────┘ └────────┘ * ``` * * It's important to note that functions passed to `pipe` must have a **single * argument** because they are only called with a single argument. * * **When to Use** * * This is useful in combination with data-last functions as a simulation of * methods: * * ```ts skip-type-checking * as.map(f).filter(g) * ``` * * becomes: * * ```ts skip-type-checking * import { pipe, Array } from "effect" * * pipe(as, Array.map(f), Array.filter(g)) * ``` * * **Example** (Chaining Arithmetic Operations) * * ```ts * import { pipe } from "effect" * * // Define simple arithmetic operations * const increment = (x: number) => x + 1 * const double = (x: number) => x * 2 * const subtractTen = (x: number) => x - 10 * * // Sequentially apply these operations using `pipe` * const result = pipe(5, increment, double, subtractTen) * * console.log(result) * // Output: 2 * ``` * * @param a - The value to pipe. * @param args - The functions to apply in sequence. * @returns The result of applying all functions in sequence to the initial value. * @since 1.0.0 */ declare function pipe(a: A): A; declare function pipe(a: A, ab: (a: A) => B): B; declare function pipe(a: A, ab: (a: A) => B, bc: (b: B) => C): C; declare function pipe(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D): D; declare function pipe(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E): E; declare function pipe(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F): F; declare function pipe(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G): G; declare function pipe(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H): H; declare function pipe(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I): I; declare function pipe(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J): J; declare function pipe(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K): K; declare function pipe(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L): L; declare function pipe(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M): M; declare function pipe(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N): N; declare function pipe(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O): O; declare function pipe(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P): P; declare function pipe(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q): Q; declare function pipe(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => R): R; declare function pipe(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => R, rs: (r: R) => S): S; declare function pipe(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => R, rs: (r: R) => S, st: (s: S) => T): T; /** * Performs left-to-right function composition. The first argument may have any arity, the remaining arguments must be unary. * * See also [`pipe`](#pipe). * * @param ab - The first function to apply. * @param bc - The second function to apply. * @param cd - The third function to apply. * @param de - The fourth function to apply. * @param ef - The fifth function to apply. * @param fg - The sixth function to apply. * @param gh - The seventh function to apply. * @param hi - The eighth function to apply. * @param ij - The ninth function to apply. * @returns A composed function that applies all given functions in sequence. * @example * ```ts * import * as assert from "node:assert" * import { flow } from "effect/Function" * * const len = (s: string): number => s.length * const double = (n: number): number => n * 2 * * const f = flow(len, double) * * assert.strictEqual(f('aaa'), 6) * ``` * * @since 1.0.0 */ declare function flow, B = never>(ab: (...a: A) => B): (...a: A) => B; declare function flow, B = never, C = never>(ab: (...a: A) => B, bc: (b: B) => C): (...a: A) => C; declare function flow, B = never, C = never, D = never>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...a: A) => D; declare function flow, B = never, C = never, D = never, E = never>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E): (...a: A) => E; declare function flow, B = never, C = never, D = never, E = never, F = never>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F): (...a: A) => F; declare function flow, B = never, C = never, D = never, E = never, F = never, G = never>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G): (...a: A) => G; declare function flow, B = never, C = never, D = never, E = never, F = never, G = never, H = never>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H): (...a: A) => H; declare function flow, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I): (...a: A) => I; declare function flow, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never>(ab: (...a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J): (...a: A) => J; /** * Retrieves a value from a Map or WeakMap if the key exists, or computes a new value if it doesn't. * * @param map - The Map or WeakMap to get from. * @param key - The key to look up in the Map or WeakMap. * @param callback - The function to call to generate a new value if the key doesn't exist. * @returns The existing value for the key, or the computed fallback value. */ declare function getOrElse(map: WeakMap, key: K, callback: () => V): V; declare function getOrElse(map: Map, key: K, callback: () => V): V; /** * Retrieves a value from a Map or WeakMap if the key exists, or computes and stores a new value if it doesn't. * * @param map - The Map or WeakMap to get from or update. * @param key - The key to look up in the Map or WeakMap. * @param callback - The function to call to generate a new value if the key doesn't exist. * @returns The existing value for the key, or the newly computed value. */ declare function getOrElseUpdate(map: WeakMap, key: K, callback: () => V): V; declare function getOrElseUpdate(map: Map, key: K, callback: () => V): V; /** * Attempts to add a value to a Set, but only if it doesn't already exist. * * @param set - The Set to potentially add to. * @param value - The value to add if it doesn't already exist in the Set. * @returns `true` if the value was added, `false` if it already existed. */ declare function tryAddToSet(set: Set, value: T): boolean; //#endregion export { NarrowedTo, Pretty, absurd, apply, compose, constFalse, constNull, constTrue, constVoid, constant, dual, flip, flow, getOrElse, getOrElseUpdate, identity, isArray, isFunction, isObject, isTruthy, not, or, pipe, pipeArguments, tryAddToSet, tupled, unit, untupled };