Exit
Represents the result of an Effect computation as a plain value.
An Exit<A, E> is either a success with an A or a failure with a Cause<E>. 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.
Combinators
Signature
declare const asVoid: <A, E>(self: Exit<A, E>) => Exit<void, E>;Combines multiple Exit values into a single Exit<void, E>.
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.
See
asVoidto discard the value of a single Exit
Signature
declare const asVoidAll: <I extends Iterable<Exit<any, any>>>(
exits: I,
) => Exit<void, I extends Iterable<Exit<infer _A, infer _E>> ? _E : never>;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.
See
Signature
declare const map: {
<A, B>(f: (a: A) => B): <E>(self: Exit<A, E>) => Exit<B, E>;
<A, E, B>(self: Exit<A, E>, f: (a: A) => B): Exit<B, E>;
};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 the typed error if the Exit is a Failure with a Fail reason. Allocates a new Exit.
Gotchas
If the Cause contains only defects or interruptions, the failure passes through unchanged.
See
Signature
declare const mapBoth: {
<E, E2, A, A2>(options: {
readonly onFailure: (e: E) => E2;
readonly onSuccess: (a: A) => A2;
}): (self: Exit<A, E>) => Exit<A2, E2>;
<A, E, E2, A2>(
self: Exit<A, E>,
options: {
readonly onFailure: (e: E) => E2;
readonly onSuccess: (a: A) => A2;
},
): Exit<A2, E2>;
};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
Only transforms typed errors (Fail reasons). If the Cause contains only defects or interruptions, the failure passes through unchanged.
See
Signature
declare const mapError: {
<E, E2>(f: (a: NoInfer<E>) => E2): <A>(self: Exit<A, E>) => Exit<A, E2>;
<A, E, E2>(self: Exit<A, E>, f: (a: NoInfer<E>) => E2): Exit<A, E2>;
};Constructors
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<never> with E = never, since defects do not appear in the typed error channel.
See
Signature
declare const die: (defect: unknown) => Exit<never>;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<never, E>.
See
Signature
declare const fail: <E>(e: E) => Exit<never, E>;Creates a failed Exit from a Cause.
When to use
Use when you already have a Cause<E> 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<never, E>. If you only have an error value, use fail instead.
See
Signature
declare const failCause: <E>(cause: Cause.Cause<E>) => Exit<never, E>;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<never> with an Interrupt cause.
See
hasInterruptsto check whether an Exit contains interruptions
Signature
declare const interrupt: (fiberId?: number) => Exit<never>;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<A> with the provided value. Does not perform any computation.
See
Signature
declare const succeed: <A>(a: A) => Exit<A>;Filtering
filterCause
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.
See
filterFailureto get the full Failure objectgetCauseto get the Cause as an Option instead
Signature
declare const filterCause: <A, E>(self: Exit<A, E>) => Result.Result<Cause.Cause<E>, Success<A>>;filterFailure
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.
See
filterSuccessfor the inversefilterCauseto extract the Cause directly
Signature
declare const filterFailure: <A, E>(
self: Exit<A, E>,
) => Result.Result<Failure<never, E>, Success<A>>;filterSuccess
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.
See
filterFailurefor the inversefilterValueto extract the raw value instead of the Success object
Signature
declare const filterSuccess: <A, E>(
self: Exit<A, E>,
) => Result.Result<Success<A>, Failure<never, E>>;filterValue
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.
See
filterSuccessto get the full Success objectgetSuccessto get the value as an Option instead
Signature
declare const filterValue: <A, E>(self: Exit<A, E>) => Result.Result<A, Failure<never, E>>;findDefect
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.
See
Signature
declare const findDefect: <A, E>(input: Exit<A, E>) => Result.Result<unknown, Exit<A, E>>;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.
See
findErrorOptionto get the error as an Option insteadfindDefectto find defects instead
Signature
declare const findError: <A, E>(input: Exit<A, E>) => Result.Result<E, Exit<A, E>>;Getters
findErrorOption
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.
See
Signature
declare const findErrorOption: <A, E>(self: Exit<A, E>) => Option<E>;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.
See
getSuccessto extract the success valuefilterCausefor filter-pipeline usage
Signature
declare const getCause: <A, E>(self: Exit<A, E>) => Option<Cause.Cause<E>>;getSuccess
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.
See
getCauseto extract the Cause of a failurefilterValuefor filter-pipeline usage
Signature
declare const getSuccess: <A, E>(self: Exit<A, E>) => Option<A>;Guards
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.
See
hasFailsto check for typed errorshasInterruptsto check for interruptions
Signature
declare const hasDies: <A, E>(self: Exit<A, E>) => self is Failure<A, E>;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.
See
hasDiesto check for defectshasInterruptsto check for interruptions
Signature
declare const hasFails: <A, E>(self: Exit<A, E>) => self is Failure<A, E>;hasInterrupts
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.
See
Signature
declare const hasInterrupts: <A, E>(self: Exit<A, E>) => self is Failure<A, E>;Checks whether an unknown value is an Exit.
When to use
Use to validate unknown values at system boundaries and narrow them to Exit<unknown, unknown>.
Details
Does not inspect the contents of the Exit. Returns true for both Success and Failure exits.
See
Signature
declare const isExit: (u: unknown) => u is Exit<unknown, unknown>;Checks whether an Exit is a Failure.
When to use
Use as a type guard to narrow Exit<A, E> to Failure<A, E> and access the cause property.
See
Signature
declare const isFailure: <A, E>(self: Exit<A, E>) => self is Failure<A, E>;Checks whether an Exit is a Success.
When to use
Use as a type guard to narrow Exit<A, E> to Success<A, E> and access the value property.
See
Signature
declare const isSuccess: <A, E>(self: Exit<A, E>) => self is Success<A, E>;Models
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<A, E> is either Success<A, E> containing a value of type A, or Failure<A, E> containing a Cause<E> describing why the computation failed.
Since Exit is also an Effect, you can yield it inside Effect.gen.
See
Signature
type Exit<A, E = never> = Success<A, E> | Failure<A, E>;A failed Exit containing a Cause.
When to use
Use when working with the failed branch of an Exit after narrowing with isFailure. Access the cause via the cause property after narrowing.
Details
The Cause<E> may contain typed errors, defects, or interruptions.
See
Signature
interface Failure<out A, out E> extends Proto<A, E> {
readonly _tag: "Failure";
readonly cause: Cause<E>;
}A successful Exit containing a value.
When to use
Use when working with the successful branch of an Exit after narrowing with isSuccess. Access the value via the value property after narrowing.
See
Signature
interface Success<out A, out E = never> extends Proto<A, E> {
readonly _tag: "Success";
readonly value: A;
}Other
Pattern Matching
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.
See
isSuccessand isFailure for simple boolean checks
Signature
declare const match: {
<A, E, X1, X2>(options: {
readonly onFailure: (cause: Cause.Cause<NoInfer<E>>) => X2;
readonly onSuccess: (a: NoInfer<A>) => X1;
}): (self: Exit<A, E>) => X1 | X2;
<A, E, X1, X2>(
self: Exit<A, E>,
options: {
readonly onFailure: (cause: Cause.Cause<E>) => X2;
readonly onSuccess: (a: A) => X1;
},
): X1 | X2;
};
Discards the success value of an Exit, replacing it with
void.When to use
Use when you need to discard a successful
Exitvalue while preserving whether theExitsucceeded or failed.Details
Failures pass through unchanged.
Allocates a new Exit if successful.
See
voidfor a pre-allocated void successasVoidAllto combine multiple exits into a single void Exit