Skip to content
Effect Days 2026 Get your ticket

Exit

40 exports Added in v2.0.0 Source

Constructors

all

Added in v2.0.0 Source

Collects all of the specified exit values into a Some<Exit<List<A>, E>>. If the provided iterable contains no elements, None will be returned.

Signature

declare const all: <A, E>(exits: Iterable<Exit<A, E>>, options?: {
readonly parallel?: boolean;
}) => Option.Option<Exit<Array<A>, E>>

die

Added in v2.0.0 Source

Constructs a new Exit.Failure from the specified unrecoverable defect.

Signature

declare const die: (defect: unknown) => Exit<never>

fail

Added in v2.0.0 Source

Constructs a new Exit.Failure from the specified recoverable error of type E.

Signature

declare const fail: <E>(error: E) => Exit<never, E>

failCause

Added in v2.0.0 Source

Constructs a new Exit.Failure from the specified Cause of type E.

Signature

declare const failCause: <E>(cause: Cause.Cause<E>) => Exit<never, E>

interrupt

Added in v2.0.0 Source

Constructs a new Exit.Failure from the specified FiberId indicating that the Fiber running an Effect workflow was terminated due to interruption.

Signature

declare const interrupt: (fiberId: FiberId.FiberId) => Exit<never>

succeed

Added in v2.0.0 Source

Constructs a new Exit.Success containing the specified value of type A.

Signature

declare const succeed: <A>(value: A) => Exit<A>

Conversions

fromEither

Added in v2.0.0 Source

Converts an Either<R, L> into an Exit<R, L>.

Signature

declare const fromEither: <R, L>(either: Either.Either<R, L>) => Exit<R, L>

fromOption

Added in v2.0.0 Source

Converts an Option<A> into an Exit<void, A>.

Signature

declare const fromOption: <A>(option: Option.Option<A>) => Exit<A, void>

Elements

exists

Added in v2.0.0 Source

Executes the predicate on the value of the specified exit if it is a Success, otherwise returns false.

Signature

declare const exists: {
<A, B>(refinement: Refinement<NoInfer<A>, B>): <E>(self: Exit<A, E>) => self is Exit<B, never>;
<A>(predicate: Predicate<NoInfer<A>>): <E>(self: Exit<A, E>) => boolean;
<A, E, B>(self: Exit<A, E>, refinement: Refinement<A, B>): self is Exit<B, never>;
<A, E>(self: Exit<A, E>, predicate: Predicate<A>): boolean;
}

Folding

match

Added in v2.0.0 Source

Signature

declare const match: {
<E, A, Z1, Z2>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Z1;
readonly onSuccess: (a: A) => Z2;
}): (self: Exit<A, E>) => Z1 | Z2;
<A, E, Z1, Z2>(self: Exit<A, E>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Z1;
readonly onSuccess: (a: A) => Z2;
}): Z1 | Z2;
}

matchEffect

Added in v2.0.0 Source

Signature

declare const matchEffect: {
<E, A2, E2, R, A, A3, E3, R2>(options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R>;
readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R2>;
}): (self: Exit<A, E>) => Effect<A2 | A3, E2 | E3, R | R2>;
<A, E, A2, E2, R, A3, E3, R2>(self: Exit<A, E>, options: {
readonly onFailure: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R>;
readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R2>;
}): Effect<A2 | A3, E2 | E3, R | R2>;
}

Getters

causeOption

Added in v2.0.0 Source

Returns a Some<Cause<E>> if the specified exit is a Failure, None otherwise.

Signature

declare const causeOption: <A, E>(self: Exit<A, E>) => Option.Option<Cause.Cause<E>>

getOrElse

Added in v2.0.0 Source

Returns the A if specified exit is a Success, otherwise returns the alternate A value computed from the specified function which receives the Cause<E> of the exit Failure.

Signature

declare const getOrElse: {
<E, A2>(orElse: (cause: Cause<E>) => A2): <A>(self: Exit<A, E>) => A2 | A;
<A, E, A2>(self: Exit<A, E>, orElse: (cause: Cause<E>) => A2): A | A2;
}

Returns true if the specified exit is a Failure and the Cause of the failure was due to interruption, false otherwise.

Signature

declare const isInterrupted: <A, E>(self: Exit<A, E>) => boolean

Mapping

as

Added in v2.0.0 Source

Maps the Success value of the specified exit to the provided constant value.

Signature

declare const as: {
<A2>(value: A2): <A, E>(self: Exit<A, E>) => Exit<A2, E>;
<A, E, A2>(self: Exit<A, E>, value: A2): Exit<A2, E>;
}

asVoid

Added in v2.0.0 Source

Maps the Success value of the specified exit to a void.

Signature

declare const asVoid: <A, E>(self: Exit<A, E>) => Exit<void, E>

map

Added in v2.0.0 Source

Maps over the Success value of the specified exit using the provided function.

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>;
}

mapBoth

Added in v2.0.0 Source

Maps over the Success and Failure cases of the specified exit using the provided functions.

Signature

declare const mapBoth: {
<E, A, E2, 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>;
}

mapError

Added in v2.0.0 Source

Maps over the error contained in the Failure of the specified exit using the provided function.

Signature

declare const mapError: {
<E, E2>(f: (e: E) => E2): <A>(self: Exit<A, E>) => Exit<A, E2>;
<A, E, E2>(self: Exit<A, E>, f: (e: E) => E2): Exit<A, E2>;
}

Maps over the Cause contained in the Failure of the specified exit using the provided function.

Signature

declare const mapErrorCause: {
<E, E2>(f: (cause: Cause<E>) => Cause<E2>): <A>(self: Exit<A, E>) => Exit<A, E2>;
<E, A, E2>(self: Exit<A, E>, f: (cause: Cause<E>) => Cause<E2>): Exit<A, E2>;
}

Models

Exit type

Added in v2.0.0 Source

An Exit<A, E = never> describes the result of a executing an Effect workflow.

There are two possible values for an Exit<A, E>:

  • Exit.Success contain a success value of type A
  • Exit.Failure contains a failure Cause of type E

Signature

type Exit<A, E = never> = Success<A, E> | Failure<A, E>

ExitUnify interface

Added in v2.0.0 Source

Signature

interface ExitUnify<A extends {
[typeSymbol]?: any;
}> extends EffectUnify<A> {
Exit?: () => A[typeof typeSymbol] extends Exit<A0, E0> | _ ? Exit<A0, E0> : never;
}

ExitUnifyIgnore interface

Added in v2.0.0 Source

Signature

interface ExitUnifyIgnore extends EffectUnifyIgnore {
Effect?: true;
}

Failure interface

Added in v2.0.0 Source

Represents a failed Effect workflow containing the Cause of the failure of type E.

Signature

interface Failure<out A, out E> extends Effect<A, E>, Pipeable, Inspectable {
readonly _op: "Failure";
readonly _tag: "Failure";
[ignoreSymbol]?: ExitUnifyIgnore;
[typeSymbol]?: unknown;
[unifySymbol]?: ExitUnify<Failure<A, E>>;
readonly cause: Cause<E>;
}

Success interface

Added in v2.0.0 Source

Represents a successful Effect workflow and containing the returned value of type A.

Signature

interface Success<out A, out E> extends Effect<A, E>, Pipeable, Inspectable {
readonly _op: "Success";
readonly _tag: "Success";
[ignoreSymbol]?: ExitUnifyIgnore;
[typeSymbol]?: unknown;
[unifySymbol]?: ExitUnify<Success<A, E>>;
readonly value: A;
}

Other

Signature

declare const void: Exit<void>

Refinements

isExit

Added in v2.0.0 Source

Returns true if the specified value is an Exit, false otherwise.

Signature

declare const isExit: (u: unknown) => u is Exit<unknown, unknown>

isFailure

Added in v2.0.0 Source

Returns true if the specified Exit is a Failure, false otherwise.

Signature

declare const isFailure: <A, E>(self: Exit<A, E>) => self is Failure<A, E>

isSuccess

Added in v2.0.0 Source

Returns true if the specified Exit is a Success, false otherwise.

Signature

declare const isSuccess: <A, E>(self: Exit<A, E>) => self is Success<A, E>

Sequencing

flatMap

Added in v2.0.0 Source

Signature

declare const flatMap: {
<A, A2, E2>(f: (a: A) => Exit<A2, E2>): <E>(self: Exit<A, E>) => Exit<A2, E2 | E>;
<A, E, E2, A2>(self: Exit<A, E>, f: (a: A) => Exit<A2, E2>): Exit<A2, E | E2>;
}

Signature

declare const flatMapEffect: {
<A, E, A2, E2, R>(f: (a: A) => Effect<Exit<A2, E>, E2, R>): (self: Exit<A, E>) => Effect<Exit<A2, E>, E2, R>;
<A, E, A2, E2, R>(self: Exit<A, E>, f: (a: A) => Effect<Exit<A2, E>, E2, R>): Effect<Exit<A2, E>, E2, R>;
}

flatten

Added in v2.0.0 Source

Signature

declare const flatten: <A, E, E2>(self: Exit<Exit<A, E>, E2>) => Exit<A, E | E2>

Traversing

Signature

declare const forEachEffect: {
<A, B, E2, R>(f: (a: A) => Effect<B, E2, R>): <E>(self: Exit<A, E>) => Effect<Exit<B, E2 | E>, never, R>;
<A, E, B, E2, R>(self: Exit<A, E>, f: (a: A) => Effect<B, E2, R>): Effect<Exit<B, E | E2>, never, R>;
}

Zipping

zip

Added in v2.0.0 Source

Sequentially zips the this result with the specified result or else returns the failed Cause<E | E2>.

Signature

declare const zip: {
<A2, E2>(that: Exit<A2, E2>): <A, E>(self: Exit<A, E>) => Exit<[A, A2], E2 | E>;
<A, E, A2, E2>(self: Exit<A, E>, that: Exit<A2, E2>): Exit<[A, A2], E | E2>;
}

zipLeft

Added in v2.0.0 Source

Sequentially zips the this result with the specified result discarding the second element of the tuple or else returns the failed Cause<E | E2>.

Signature

declare const zipLeft: {
<A2, E2>(that: Exit<A2, E2>): <A, E>(self: Exit<A, E>) => Exit<A, E2 | E>;
<A, E, A2, E2>(self: Exit<A, E>, that: Exit<A2, E2>): Exit<A, E | E2>;
}

zipPar

Added in v2.0.0 Source

Parallelly zips the this result with the specified result or else returns the failed Cause<E | E2>.

Signature

declare const zipPar: {
<A2, E2>(that: Exit<A2, E2>): <A, E>(self: Exit<A, E>) => Exit<[A, A2], E2 | E>;
<A, E, A2, E2>(self: Exit<A, E>, that: Exit<A2, E2>): Exit<[A, A2], E | E2>;
}

zipParLeft

Added in v2.0.0 Source

Parallelly zips the this result with the specified result discarding the second element of the tuple or else returns the failed Cause<E | E2>.

Signature

declare const zipParLeft: {
<A2, E2>(that: Exit<A2, E2>): <A, E>(self: Exit<A, E>) => Exit<A, E2 | E>;
<A, E, A2, E2>(self: Exit<A, E>, that: Exit<A2, E2>): Exit<A, E | E2>;
}

zipParRight

Added in v2.0.0 Source

Parallelly zips the this result with the specified result discarding the first element of the tuple or else returns the failed Cause<E | E2>.

Signature

declare const zipParRight: {
<A2, E2>(that: Exit<A2, E2>): <A, E>(self: Exit<A, E>) => Exit<A2, E2 | E>;
<A, E, A2, E2>(self: Exit<A, E>, that: Exit<A2, E2>): Exit<A2, E | E2>;
}

zipRight

Added in v2.0.0 Source

Sequentially zips the this result with the specified result discarding the first element of the tuple or else returns the failed Cause<E | E2>.

Signature

declare const zipRight: {
<A2, E2>(that: Exit<A2, E2>): <A, E>(self: Exit<A, E>) => Exit<A2, E2 | E>;
<A, E, A2, E2>(self: Exit<A, E>, that: Exit<A2, E2>): Exit<A2, E | E2>;
}

zipWith

Added in v2.0.0 Source

Zips this exit together with that exit using the specified combination functions.

Signature

declare const zipWith: {
<B, E2, A, C, E>(that: Exit<B, E2>, options: {
readonly onFailure: (cause: Cause.Cause<E>, cause2: Cause.Cause<E2>) => Cause.Cause<any>;
readonly onSuccess: (a: A, b: B) => C;
}): (self: Exit<A, E>) => Exit<C, any>;
<A, E, B, E2, C>(self: Exit<A, E>, that: Exit<B, E2>, options: {
readonly onFailure: (cause: Cause.Cause<E>, cause2: Cause.Cause<E2>) => Cause.Cause<E | E2>;
readonly onSuccess: (a: A, b: B) => C;
}): Exit<C, E | E2>;
}