Skip to main content Link Search Menu Expand Document (external link)

Exit overview

Added in v2.0.0


Table of contents


constructors

all

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

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

Added in v2.0.0

die

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

Signature

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

Added in v2.0.0

fail

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

Signature

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

Added in v2.0.0

failCause

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

Signature

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

Added in v2.0.0

interrupt

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

Signature

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

Added in v2.0.0

succeed

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

Signature

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

Added in v2.0.0

void

Represents an Exit which succeeds with undefined.

Signature

export declare const void: Exit<void, never>

Added in v2.0.0

conversions

fromEither

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

Signature

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

Added in v2.0.0

fromOption

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

Signature

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

Added in v2.0.0

elements

exists

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

Signature

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

Added in v2.0.0

folding

match

Signature

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

Added in v2.0.0

matchEffect

Signature

export 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.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.Effect<A2 | A3, E2 | E3, R | R2>
}

Added in v2.0.0

getters

causeOption

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

Signature

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

Added in v2.0.0

getOrElse

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

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

Added in v2.0.0

isInterrupted

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

Signature

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

Added in v2.0.0

mapping

as

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

Signature

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

Added in v2.0.0

asVoid

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

Signature

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

Added in v2.0.0

map

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

Signature

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

Added in v2.0.0

mapBoth

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

Signature

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

Added in v2.0.0

mapError

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

Signature

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

Added in v2.0.0

mapErrorCause

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

Signature

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

Added in v2.0.0

models

Exit (type alias)

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

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

Added in v2.0.0

ExitUnify (interface)

Signature

export interface ExitUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
  Exit?: () => A[Unify.typeSymbol] extends Exit<infer A0, infer E0> | infer _ ? Exit<A0, E0> : never
}

Added in v2.0.0

ExitUnifyIgnore (interface)

Signature

export interface ExitUnifyIgnore extends Effect.EffectUnifyIgnore {
  Effect?: true
}

Added in v2.0.0

Failure (interface)

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

Signature

export interface Failure<out A, out E> extends Effect.Effect<A, E>, Pipeable, Inspectable {
  readonly _tag: "Failure"
  readonly _op: "Failure"
  readonly cause: Cause.Cause<E>
  [Unify.typeSymbol]?: unknown
  [Unify.unifySymbol]?: ExitUnify<this>
  [Unify.ignoreSymbol]?: ExitUnifyIgnore
  /** @internal */
  readonly effect_instruction_i0: Cause.Cause<E>
}

Added in v2.0.0

Success (interface)

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

Signature

export interface Success<out A, out E> extends Effect.Effect<A, E>, Pipeable, Inspectable {
  readonly _tag: "Success"
  readonly _op: "Success"
  readonly value: A
  [Unify.typeSymbol]?: unknown
  [Unify.unifySymbol]?: ExitUnify<this>
  [Unify.ignoreSymbol]?: ExitUnifyIgnore
  /** @internal */
  readonly effect_instruction_i0: A
}

Added in v2.0.0

refinements

isExit

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

Signature

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

Added in v2.0.0

isFailure

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

Signature

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

Added in v2.0.0

isSuccess

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

Signature

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

Added in v2.0.0

sequencing

flatMap

Signature

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

Added in v2.0.0

flatMapEffect

Signature

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

Added in v2.0.0

flatten

Signature

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

Added in v2.0.0

traversing

forEachEffect

Signature

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

Added in v2.0.0

zipping

zip

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

Signature

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

Added in v2.0.0

zipLeft

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

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

Added in v2.0.0

zipPar

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

Signature

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

Added in v2.0.0

zipParLeft

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

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

Added in v2.0.0

zipParRight

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

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

Added in v2.0.0

zipRight

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

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

Added in v2.0.0

zipWith

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

Signature

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

Added in v2.0.0