/** * Represents the result of an Effect computation as a plain value. * * An `Exit` is either a success with an `A` or a failure with a * `Cause`. The failure cause preserves typed errors, defects, and * interruptions after a workflow has finished. Use this module when completed * Effect results need to be inspected, transformed, filtered, or matched * synchronously as data. * * @stability stable * @since 2.0.0 */ import type * as Cause from "./Cause.ts"; import type * as Effect from "./Effect.ts"; import type { Option } from "./Option.ts"; import type * as Result from "./Result.ts"; import type { NoInfer } from "./Types.ts"; declare const TypeId: "~effect/Exit"; /** * Represents the result of an Effect computation. * * **When to use** * * Use when you need to synchronously inspect whether an Effect computation * succeeded or failed. * * **Details** * * An `Exit` is either `Success` containing a value of type `A`, or * `Failure` containing a `Cause` describing why the computation * failed. * * Since `Exit` is also an `Effect`, you can yield it inside `Effect.gen`. * * **Example** (Pattern matching on an Exit) * * ```ts import.meta.vitest * import { Exit } from "effect" * * const success: Exit.Exit = Exit.succeed(42) * const failure: Exit.Exit = Exit.fail("error") * * Exit.match(success, { * onSuccess: (value) => `Got value: ${value}`, * onFailure: (cause) => `Got error: ${cause}` * }) // => "Got value: 42" * ``` * * @see {@link Success} for the success case * @see {@link Failure} for the failure case * @see {@link match} for pattern matching * * @stability stable * @category models * @since 2.0.0 */ export type Exit = Success | Failure; /** * Namespace containing helper types shared by `Exit` values. * * **When to use** * * Use to reference helper types that describe the shared structure of `Exit` * values. * * @stability stable * @since 2.0.0 */ export declare namespace Exit { /** * Base interface shared by both Success and Failure. * * **When to use** * * Use to describe the common protocol implemented by every `Exit` value. * * **Details** * * Every Exit is also an Effect, so you can yield it in `Effect.gen`. * * @category models * @since 4.0.0 */ interface Proto extends Effect.Effect { readonly [TypeId]: typeof TypeId; } } /** * A successful Exit containing a value. * * **When to use** * * Use when working with the successful branch of an `Exit` after narrowing * with {@link isSuccess}. Access the value via the `value` property after * narrowing. * * **Example** (Accessing the success value) * * ```ts import.meta.vitest * import { Exit } from "effect" * * const success = Exit.succeed(42) * * if (Exit.isSuccess(success)) { * success.value // => 42 * } * ``` * * @see {@link isSuccess} to narrow an Exit to Success * @see {@link Failure} for the failure counterpart * * @stability stable * @category models * @since 2.0.0 */ export interface Success extends Exit.Proto { readonly _tag: "Success"; readonly value: A; } /** * A failed Exit containing a Cause. * * **When to use** * * Use when working with the failed branch of an `Exit` after narrowing with * {@link isFailure}. Access the cause via the `cause` property after * narrowing. * * **Details** * * The `Cause` may contain typed errors, defects, or interruptions. * * **Example** (Accessing the failure cause) * * ```ts import.meta.vitest * import { Cause, Exit } from "effect" * * const failure = Exit.fail("something went wrong") * * if (Exit.isFailure(failure)) { * failure.cause // => Cause.fail("something went wrong") * } * ``` * * @see {@link isFailure} to narrow an Exit to Failure * @see {@link Success} for the success counterpart * * @stability stable * @category models * @since 2.0.0 */ export interface Failure extends Exit.Proto { readonly _tag: "Failure"; readonly cause: Cause.Cause; } /** * Checks whether an unknown value is an Exit. * * **When to use** * * Use to validate unknown values at system boundaries and narrow them to * `Exit`. * * **Details** * * Does not inspect the contents of the Exit. Returns `true` for both Success * and Failure exits. * * **Example** (Checking if a value is an Exit) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.isExit(Exit.succeed(42)) // => true * Exit.isExit(Exit.fail("err")) // => true * Exit.isExit("not an exit") // => false * ``` * * @see {@link isSuccess} to check for a successful Exit * @see {@link isFailure} to check for a failed Exit * * @stability stable * @category guards * @since 2.0.0 */ export declare const isExit: (u: unknown) => u is Exit; /** * Creates a successful Exit containing the given value. * * **When to use** * * Use when you need an Exit that contains a known success value. * * **Details** * * Returns a `Success` with the provided value. Does not perform any * computation. * * **Example** (Creating a successful Exit) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.succeed(42) // => Exit.succeed(42) * ``` * * @see {@link fail} to create a failed Exit * @see {@link void_ void} for a pre-allocated success with no value * * @stability stable * @category constructors * @since 2.0.0 */ export declare const succeed: (a: A) => Exit; /** * Creates a failed Exit from a Cause. * * **When to use** * * Use when you already have a `Cause` and want to wrap it in an Exit * for advanced error handling where you need full control over the Cause * structure. * * **Details** * * Returns a `Failure`. If you only have an error value, use * {@link fail} instead. * * **Example** (Creating a failed Exit from a Cause) * * ```ts import.meta.vitest * import { Cause, Exit } from "effect" * * Exit.failCause(Cause.fail("Something went wrong")) // => Exit.fail("Something went wrong") * ``` * * @see {@link fail} to create a Failure from a plain error value * @see {@link die} to create a Failure from a defect * * @stability stable * @category constructors * @since 2.0.0 */ export declare const failCause: (cause: Cause.Cause) => Exit; /** * Creates a failed Exit from a typed error value. * * **When to use** * * Use when you need to represent an expected typed failure as an `Exit`. * * **Details** * * The error is wrapped in a `Cause.Fail` internally. * * Returns a `Failure`. * * **Example** (Creating a failed Exit) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.fail("Something went wrong") // => Exit.fail("Something went wrong") * ``` * * @see {@link succeed} to create a successful Exit * @see {@link die} to create a Failure from an unexpected defect * @see {@link failCause} to create a Failure from a full Cause * * @stability stable * @category constructors * @since 2.0.0 */ export declare const fail: (e: E) => Exit; /** * Creates a failed Exit from a defect (unexpected error). * * **When to use** * * Use when you need unexpected, unrecoverable errors that should not appear in * the typed error channel. * * **Details** * * The defect is wrapped in a `Cause.Die` internally. * * Returns a `Failure` with `E = never`, since defects do not appear in * the typed error channel. * * **Example** (Creating a defect Exit) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.die("Unexpected error") // => Exit.die("Unexpected error") * ``` * * @see {@link fail} to create a Failure from a typed error * @see {@link hasDies} to check whether an Exit contains defects * * @stability stable * @category constructors * @since 2.0.0 */ export declare const die: (defect: unknown) => Exit; /** * Creates a failed Exit representing fiber interruption. * * **When to use** * * Use to signal that a fiber was interrupted. * * **Details** * * Optionally pass a fiber ID to identify which fiber was interrupted. Returns * a `Failure` with an `Interrupt` cause. * * **Example** (Creating an interruption Exit) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.interrupt(123) // => Exit.interrupt(123) * ``` * * @see {@link hasInterrupts} to check whether an Exit contains interruptions * * @stability stable * @category constructors * @since 2.0.0 */ export declare const interrupt: (fiberId?: number | undefined) => Exit; declare const void_: Exit; export { /** * Provides a pre-allocated successful Exit with a `void` value. * * **When to use** * * Use when you need a shared successful `Exit` with no meaningful value. * * **Details** * * Equivalent to `Exit.succeed(undefined)` but shared as a single instance, * avoiding allocation for a common case. * * **Example** (Referencing the void Exit) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.void // => Exit.succeed(undefined) * ``` * * @see {@link succeed} to create a success with a specific value * @see {@link asVoid} to discard the value of an existing Exit * * @stability stable * @category constructors * @since 2.0.0 */ void_ as void }; /** * Checks whether an Exit is a Success. * * **When to use** * * Use as a type guard to narrow `Exit` to `Success` and access the * `value` property. * * **Example** (Narrowing to success) * * ```ts import.meta.vitest * import { Exit } from "effect" * * const exit = Exit.succeed(42) * * if (Exit.isSuccess(exit)) { * exit.value // => 42 * } * ``` * * @see {@link isFailure} for the opposite check * @see {@link match} for exhaustive pattern matching * * @stability stable * @category guards * @since 2.0.0 */ export declare const isSuccess: (self: Exit) => self is Success; /** * Checks whether an Exit is a Failure. * * **When to use** * * Use as a type guard to narrow `Exit` to `Failure` and access the * `cause` property. * * **Example** (Narrowing to failure) * * ```ts import.meta.vitest * import { Cause, Exit } from "effect" * * const exit = Exit.fail("error") * * if (Exit.isFailure(exit)) { * exit.cause // => Cause.fail("error") * } * ``` * * @see {@link isSuccess} for the opposite check * @see {@link match} for exhaustive pattern matching * * @stability stable * @category guards * @since 2.0.0 */ export declare const isFailure: (self: Exit) => self is Failure; /** * Checks whether a failed Exit contains typed errors (Fail reasons). * * **When to use** * * Use to distinguish typed failures from defects or interruptions. * * **Details** * * Returns `false` for successful exits. Only checks for `Fail` reasons in the * Cause. A Cause with only `Die` or `Interrupt` reasons returns `false`. * * **Example** (Checking for typed errors) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.hasFails(Exit.fail("err")) // => true * Exit.hasFails(Exit.die("bug")) // => false * Exit.hasFails(Exit.succeed(42)) // => false * ``` * * @see {@link hasDies} to check for defects * @see {@link hasInterrupts} to check for interruptions * * @stability stable * @category guards * @since 4.0.0 */ export declare const hasFails: (self: Exit) => self is Failure; /** * Checks whether a failed Exit contains defects (Die reasons). * * **When to use** * * Use to check whether an `Exit` failure cause contains unexpected errors. * * **Details** * * Returns `false` for successful exits. Only checks for `Die` reasons in the * Cause. A Cause with only `Fail` or `Interrupt` reasons returns `false`. * * **Example** (Checking for defects) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.hasDies(Exit.die("bug")) // => true * Exit.hasDies(Exit.fail("err")) // => false * Exit.hasDies(Exit.succeed(42)) // => false * ``` * * @see {@link hasFails} to check for typed errors * @see {@link hasInterrupts} to check for interruptions * * @stability stable * @category guards * @since 4.0.0 */ export declare const hasDies: (self: Exit) => self is Failure; /** * Checks whether a failed Exit contains interruptions (Interrupt reasons). * * **When to use** * * Use to check whether an `Exit` contains fiber interruption. * * **Details** * * Returns `false` for successful exits. Only checks for `Interrupt` reasons in * the Cause. A Cause with only `Fail` or `Die` reasons returns `false`. * * **Example** (Checking for interruptions) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.hasInterrupts(Exit.interrupt(1)) // => true * Exit.hasInterrupts(Exit.fail("err")) // => false * Exit.hasInterrupts(Exit.succeed(42)) // => false * ``` * * @see {@link hasFails} to check for typed errors * @see {@link hasDies} to check for defects * * @stability stable * @category guards * @since 4.0.0 */ export declare const hasInterrupts: (self: Exit) => self is Failure; /** * Extracts the Success variant from an Exit as a Result. * * **When to use** * * Use when composing Exit checks with `Filter` or other `Result`-based * filtering APIs and you want the full Success wrapper. * * **Details** * * Returns `Result.succeed(success)` when the Exit is a Success, or * `Result.fail(failure)` with the original Failure otherwise. * * **Gotchas** * * This is not an `Option` accessor or an Effect failure. A failed extraction is * represented as data in the `Result` failure channel. * * **Example** (Filtering for success) * * ```ts import.meta.vitest * import { Exit, Result } from "effect" * * Exit.filterSuccess(Exit.succeed(42)) // => Result.succeed(Exit.succeed(42)) * ``` * * @see {@link filterFailure} for the inverse * @see {@link filterValue} to extract the raw value instead of the Success object * * @stability stable * @category filtering * @since 4.0.0 */ export declare const filterSuccess: (self: Exit) => Result.Result, Failure>; /** * Extracts the success value from an Exit as a Result. * * **When to use** * * Use when composing Exit checks with `Filter` or other `Result`-based * filtering APIs and you want the raw success value rather than the Success * wrapper. * * **Details** * * Returns `Result.succeed(value)` when the Exit is a Success, or * `Result.fail(failure)` with the original Failure otherwise. * * **Gotchas** * * This is not an `Option` accessor or an Effect failure. A failed extraction is * represented as data in the `Result` failure channel. * * **Example** (Filtering for the value) * * ```ts import.meta.vitest * import { Exit, Result } from "effect" * * Exit.filterValue(Exit.succeed(42)) // => Result.succeed(42) * ``` * * @see {@link filterSuccess} to get the full Success object * @see {@link getSuccess} to get the value as an Option instead * * @stability stable * @category filtering * @since 4.0.0 */ export declare const filterValue: (self: Exit) => Result.Result>; /** * Extracts the Failure variant from an Exit as a Result. * * **When to use** * * Use when composing Exit checks with `Filter` or other `Result`-based * filtering APIs and you want the full Failure wrapper. * * **Details** * * Returns `Result.succeed(failure)` when the Exit is a Failure, or * `Result.fail(success)` with the original Success otherwise. * * **Gotchas** * * This is not an `Option` accessor or an Effect failure. A failed extraction is * represented as data in the `Result` failure channel. * * **Example** (Filtering for failure) * * ```ts import.meta.vitest * import { Exit, Result } from "effect" * * Exit.filterFailure(Exit.fail("err")) // => Result.succeed(Exit.fail("err")) * ``` * * @see {@link filterSuccess} for the inverse * @see {@link filterCause} to extract the Cause directly * * @stability stable * @category filtering * @since 4.0.0 */ export declare const filterFailure: (self: Exit) => Result.Result, Success>; /** * Extracts the Cause from a failed Exit as a Result. * * **When to use** * * Use when composing Exit checks with `Filter` or other `Result`-based * filtering APIs and you want the raw Cause rather than the Failure wrapper. * * **Details** * * Returns `Result.succeed(cause)` when the Exit is a Failure, or * `Result.fail(success)` with the original Success otherwise. * * **Gotchas** * * This is not an `Option` accessor or an Effect failure. A failed extraction is * represented as data in the `Result` failure channel. * * **Example** (Filtering for the cause) * * ```ts import.meta.vitest * import { Cause, Exit, Result } from "effect" * * Exit.filterCause(Exit.fail("err")) // => Result.succeed(Cause.fail("err")) * ``` * * @see {@link filterFailure} to get the full Failure object * @see {@link getCause} to get the Cause as an Option instead * * @stability stable * @category filtering * @since 4.0.0 */ export declare const filterCause: (self: Exit) => Result.Result, Success>; /** * Extracts the first typed error value from a failed Exit as a Result. * * **When to use** * * Use when you need the first typed error from an `Exit` as a `Result` for * `Filter` or other `Result`-based filtering APIs. * * **Details** * * Returns `Result.succeed(error)` when the Cause contains a Fail reason, or * `Result.fail(exit)` with the original Exit otherwise. * * **Gotchas** * * Only finds the first Fail reason. If the Cause has multiple errors, the rest * are ignored. * * **Example** (Finding the first typed error) * * ```ts import.meta.vitest * import { Exit, Result } from "effect" * * Exit.findError(Exit.fail("not found")) // => Result.succeed("not found") * Exit.findError(Exit.die("bug")) // => Result.fail(Exit.die("bug")) * ``` * * @see {@link findErrorOption} to get the error as an Option instead * @see {@link findDefect} to find defects instead * * @stability stable * @category filtering * @since 4.0.0 */ export declare const findError: (input: Exit) => Result.Result>; /** * Extracts the first defect from a failed Exit as a Result. * * **When to use** * * Use when you need the first defect from an `Exit` as a `Result` for * `Filter` or other `Result`-based filtering APIs. * * **Details** * * Returns `Result.succeed(defect)` when the Cause contains a Die reason, or * `Result.fail(exit)` with the original Exit otherwise. * * **Gotchas** * * Only finds the first Die reason. If the Cause has multiple defects, the rest * are ignored. * * **Example** (Finding the first defect) * * ```ts import.meta.vitest * import { Exit, Result } from "effect" * * Exit.findDefect(Exit.die("boom")) // => Result.succeed("boom") * Exit.findDefect(Exit.fail("err")) // => Result.fail(Exit.fail("err")) * ``` * * @see {@link findError} to find typed errors instead * @see {@link hasDies} to check for defects without extracting them * * @stability stable * @category filtering * @since 4.0.0 */ export declare const findDefect: (input: Exit) => Result.Result>; /** * Pattern matches on an Exit, handling both success and failure cases. * * **When to use** * * Use when you need exhaustive handling of both `Exit` success and failure * outcomes. * * **Details** * * Calls `onSuccess` with the value if the Exit is a Success, and calls * `onFailure` with the Cause if the Exit is a Failure. * * **Example** (Matching on an Exit) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.match(Exit.succeed(42), { * onSuccess: (value) => `Got: ${value}`, * onFailure: () => "Failed" * }) // => "Got: 42" * ``` * * @see {@link isSuccess} and {@link isFailure} for simple boolean checks * * @stability stable * @category pattern matching * @since 2.0.0 */ export declare const match: { /** * Pattern matches on an Exit, handling both success and failure cases. * * **When to use** * * Use when you need exhaustive handling of both `Exit` success and failure * outcomes. * * **Details** * * Calls `onSuccess` with the value if the Exit is a Success, and calls * `onFailure` with the Cause if the Exit is a Failure. * * **Example** (Matching on an Exit) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.match(Exit.succeed(42), { * onSuccess: (value) => `Got: ${value}`, * onFailure: () => "Failed" * }) // => "Got: 42" * ``` * * @see {@link isSuccess} and {@link isFailure} for simple boolean checks * * @stability stable * @category pattern matching * @since 2.0.0 */ (options: { readonly onSuccess: (a: NoInfer) => X1; readonly onFailure: (cause: Cause.Cause>) => X2; }): (self: Exit) => X1 | X2; /** * Pattern matches on an Exit, handling both success and failure cases. * * **When to use** * * Use when you need exhaustive handling of both `Exit` success and failure * outcomes. * * **Details** * * Calls `onSuccess` with the value if the Exit is a Success, and calls * `onFailure` with the Cause if the Exit is a Failure. * * **Example** (Matching on an Exit) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.match(Exit.succeed(42), { * onSuccess: (value) => `Got: ${value}`, * onFailure: () => "Failed" * }) // => "Got: 42" * ``` * * @see {@link isSuccess} and {@link isFailure} for simple boolean checks * * @stability stable * @category pattern matching * @since 2.0.0 */ (self: Exit, options: { readonly onSuccess: (a: A) => X1; readonly onFailure: (cause: Cause.Cause) => X2; }): X1 | X2; }; /** * Transforms the success value of an Exit using the given function. * * **When to use** * * Use to apply a transformation to the value inside a successful Exit * * **Details** * * Failures pass through unchanged. * * Allocates a new Exit if successful. * * **Example** (Mapping over a success) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.map(Exit.succeed(21), (x) => x * 2) // => Exit.succeed(42) * ``` * * @see {@link mapError} to transform the error * @see {@link mapBoth} to transform both success and error * * @stability stable * @category combinators * @since 2.0.0 */ export declare const map: { /** * Transforms the success value of an Exit using the given function. * * **When to use** * * Use to apply a transformation to the value inside a successful Exit * * **Details** * * Failures pass through unchanged. * * Allocates a new Exit if successful. * * **Example** (Mapping over a success) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.map(Exit.succeed(21), (x) => x * 2) // => Exit.succeed(42) * ``` * * @see {@link mapError} to transform the error * @see {@link mapBoth} to transform both success and error * * @stability stable * @category combinators * @since 2.0.0 */ (f: (a: A) => B): (self: Exit) => Exit; /** * Transforms the success value of an Exit using the given function. * * **When to use** * * Use to apply a transformation to the value inside a successful Exit * * **Details** * * Failures pass through unchanged. * * Allocates a new Exit if successful. * * **Example** (Mapping over a success) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.map(Exit.succeed(21), (x) => x * 2) // => Exit.succeed(42) * ``` * * @see {@link mapError} to transform the error * @see {@link mapBoth} to transform both success and error * * @stability stable * @category combinators * @since 2.0.0 */ (self: Exit, f: (a: A) => B): Exit; }; /** * Transforms the typed error of a failed Exit using the given function. * * **When to use** * * Use to remap typed errors while preserving the Exit structure * * **Details** * * Successes pass through unchanged. * * Allocates a new Exit if the error is transformed. * * **Gotchas** * * Maps every typed error in the cause, preserving defects, interrupts and * reason order. Unlike typed recovery, mapping does not convert errors to defects. * * If the Cause contains only defects or interruptions, no mapper is called. * * **Example** (Mapping over an error) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.mapError(Exit.fail("bad input"), (error) => error.toUpperCase()) // => Exit.fail("BAD INPUT") * ``` * * @see {@link map} to transform the success value * @see {@link mapBoth} to transform both success and error * * @stability stable * @category combinators * @since 2.0.0 */ export declare const mapError: { /** * Transforms the typed error of a failed Exit using the given function. * * **When to use** * * Use to remap typed errors while preserving the Exit structure * * **Details** * * Successes pass through unchanged. * * Allocates a new Exit if the error is transformed. * * **Gotchas** * * Maps every typed error in the cause, preserving defects, interrupts and * reason order. Unlike typed recovery, mapping does not convert errors to defects. * * If the Cause contains only defects or interruptions, no mapper is called. * * **Example** (Mapping over an error) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.mapError(Exit.fail("bad input"), (error) => error.toUpperCase()) // => Exit.fail("BAD INPUT") * ``` * * @see {@link map} to transform the success value * @see {@link mapBoth} to transform both success and error * * @stability stable * @category combinators * @since 2.0.0 */ (f: (a: NoInfer) => E2): (self: Exit) => Exit; /** * Transforms the typed error of a failed Exit using the given function. * * **When to use** * * Use to remap typed errors while preserving the Exit structure * * **Details** * * Successes pass through unchanged. * * Allocates a new Exit if the error is transformed. * * **Gotchas** * * Maps every typed error in the cause, preserving defects, interrupts and * reason order. Unlike typed recovery, mapping does not convert errors to defects. * * If the Cause contains only defects or interruptions, no mapper is called. * * **Example** (Mapping over an error) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.mapError(Exit.fail("bad input"), (error) => error.toUpperCase()) // => Exit.fail("BAD INPUT") * ``` * * @see {@link map} to transform the success value * @see {@link mapBoth} to transform both success and error * * @stability stable * @category combinators * @since 2.0.0 */ (self: Exit, f: (a: NoInfer) => E2): Exit; }; /** * Transforms both the success value and typed error of an Exit. * * **When to use** * * Use when you need to remap both channels in one step. * * **Details** * * `onSuccess` transforms the value if the Exit is a Success. `onFailure` * transforms each typed error if the Exit is a Failure with Fail reasons. * Allocates a new Exit. * * **Gotchas** * * Maps every typed error in the cause, preserving defects, interrupts and * reason order. Unlike typed recovery, mapping does not convert errors to defects. * * If the Cause contains only defects or interruptions, the failure passes * through unchanged. * * **Example** (Mapping both channels) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.mapBoth(Exit.succeed(42), { * onSuccess: (x) => String(x), * onFailure: (error: string) => error.toUpperCase() * }) // => Exit.succeed("42") * ``` * * @see {@link map} to transform only the success value * @see {@link mapError} to transform only the error * * @stability stable * @category combinators * @since 2.0.0 */ export declare const mapBoth: { /** * Transforms both the success value and typed error of an Exit. * * **When to use** * * Use when you need to remap both channels in one step. * * **Details** * * `onSuccess` transforms the value if the Exit is a Success. `onFailure` * transforms each typed error if the Exit is a Failure with Fail reasons. * Allocates a new Exit. * * **Gotchas** * * Maps every typed error in the cause, preserving defects, interrupts and * reason order. Unlike typed recovery, mapping does not convert errors to defects. * * If the Cause contains only defects or interruptions, the failure passes * through unchanged. * * **Example** (Mapping both channels) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.mapBoth(Exit.succeed(42), { * onSuccess: (x) => String(x), * onFailure: (error: string) => error.toUpperCase() * }) // => Exit.succeed("42") * ``` * * @see {@link map} to transform only the success value * @see {@link mapError} to transform only the error * * @stability stable * @category combinators * @since 2.0.0 */ (options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2; }): (self: Exit) => Exit; /** * Transforms both the success value and typed error of an Exit. * * **When to use** * * Use when you need to remap both channels in one step. * * **Details** * * `onSuccess` transforms the value if the Exit is a Success. `onFailure` * transforms each typed error if the Exit is a Failure with Fail reasons. * Allocates a new Exit. * * **Gotchas** * * Maps every typed error in the cause, preserving defects, interrupts and * reason order. Unlike typed recovery, mapping does not convert errors to defects. * * If the Cause contains only defects or interruptions, the failure passes * through unchanged. * * **Example** (Mapping both channels) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.mapBoth(Exit.succeed(42), { * onSuccess: (x) => String(x), * onFailure: (error: string) => error.toUpperCase() * }) // => Exit.succeed("42") * ``` * * @see {@link map} to transform only the success value * @see {@link mapError} to transform only the error * * @stability stable * @category combinators * @since 2.0.0 */ (self: Exit, options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2; }): Exit; }; /** * Discards the success value of an Exit, replacing it with `void`. * * **When to use** * * Use when you need to discard a successful `Exit` value while preserving * whether the `Exit` succeeded or failed. * * **Details** * * Failures pass through unchanged. * * Allocates a new Exit if successful. * * **Example** (Discarding the success value) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.asVoid(Exit.succeed(42)) // => Exit.succeed(undefined) * ``` * * @see {@link void_ void} for a pre-allocated void success * @see {@link asVoidAll} to combine multiple exits into a single void Exit * * @stability stable * @category combinators * @since 2.0.0 */ export declare const asVoid: (self: Exit) => Exit; /** * Combines multiple Exit values into a single `Exit`. * * **When to use** * * Use to validate that all exits in a collection succeeded * * **Details** * * If all exits are successful, this returns a void success. If any exit is a * failure, this returns a single failure with all error causes combined. * * Iterates over the entire collection. Collects all failure causes, not just * the first. * * **Example** (Combining exits) * * ```ts import.meta.vitest * import { Exit } from "effect" * * Exit.asVoidAll([Exit.succeed(1), Exit.succeed(2), Exit.succeed(3)]) // => Exit.succeed(undefined) * Exit.asVoidAll([Exit.succeed(1), Exit.fail("err"), Exit.succeed(3)]) // => Exit.fail("err") * ``` * * @see {@link asVoid} to discard the value of a single Exit * * @stability stable * @category combinators * @since 4.0.0 */ export declare const asVoidAll: >>(exits: I) => Exit> ? _E : never>; /** * Returns the success value of an Exit as an Option. * * **When to use** * * Use when you need the success value from an `Exit` as an `Option` instead of * pattern matching. * * **Details** * * Returns `Option.some(value)` for a Success and `Option.none()` for a Failure. * * **Example** (Getting the success value) * * ```ts import.meta.vitest * import { Exit, Option } from "effect" * * Exit.getSuccess(Exit.succeed(42)) // => Option.some(42) * Exit.getSuccess(Exit.fail("err")) // => Option.none() * ``` * * @see {@link getCause} to extract the Cause of a failure * @see {@link filterValue} for filter-pipeline usage * * @stability stable * @category getters * @since 4.0.0 */ export declare const getSuccess: (self: Exit) => Option; /** * Returns the Cause of a failed Exit as an Option. * * **When to use** * * Use when you need the failure `Cause` from an `Exit` as an `Option` instead * of pattern matching. * * **Details** * * Returns `Option.some(cause)` for a Failure and `Option.none()` for a Success. * * **Example** (Getting the failure cause) * * ```ts import.meta.vitest * import { Cause, Exit, Option } from "effect" * * Exit.getCause(Exit.fail("err")) // => Option.some(Cause.fail("err")) * Exit.getCause(Exit.succeed(42)) // => Option.none() * ``` * * @see {@link getSuccess} to extract the success value * @see {@link filterCause} for filter-pipeline usage * * @stability stable * @category getters * @since 4.0.0 */ export declare const getCause: (self: Exit) => Option>; /** * Returns the first typed error from a failed Exit as an Option. * * **When to use** * * Use when you need the first typed error from an `Exit` as an `Option`, * ignoring successes and non-typed failures. * * **Details** * * Returns `Option.some(error)` if the Cause contains a Fail reason. Successes, * defect-only failures, and interrupt-only failures return `Option.none()`. * * **Gotchas** * * Only finds the first Fail reason. If the Cause has multiple typed errors, * the rest are ignored. * * **Example** (Getting the first error) * * ```ts import.meta.vitest * import { Exit, Option } from "effect" * * Exit.findErrorOption(Exit.fail("err")) // => Option.some("err") * Exit.findErrorOption(Exit.die("bug")) // => Option.none() * Exit.findErrorOption(Exit.succeed(42)) // => Option.none() * ``` * * @see {@link findError} for filter-pipeline usage * @see {@link getCause} to get the full Cause as an Option * * @stability stable * @category getters * @since 4.0.0 */ export declare const findErrorOption: (self: Exit) => Option; //# sourceMappingURL=Exit.d.ts.map