/** * @since 1.0.0 */ import type * as Either from "@effect/data/Either" import type { Inspectable } from "@effect/data/Inspectable" import type * as Option from "@effect/data/Option" import type { Pipeable } from "@effect/data/Pipeable" import type { Predicate } from "@effect/data/Predicate" import type * as Unify from "@effect/data/Unify" import type * as Cause from "@effect/io/Cause" import type * as Effect from "@effect/io/Effect" import type * as FiberId from "@effect/io/FiberId" import * as core from "@effect/io/internal/core" /** * An `Exit` describes the result of a executing an `Effect` workflow. * * There are two possible values for an `Exit`: * - `Exit.Success` contain a success value of type `A` * - `Exit.Failure` contains a failure `Cause` of type `E` * * @since 1.0.0 * @category models */ export type Exit = Failure | Success /** * Represents a failed `Effect` workflow containing the `Cause` of the failure * of type `E`. * * @since 1.0.0 * @category models */ export interface Failure extends Effect.Effect, Pipeable, Inspectable { readonly _tag: "Failure" readonly cause: Cause.Cause [Unify.typeSymbol]?: unknown [Unify.unifySymbol]?: ExitUnify [Unify.blacklistSymbol]?: ExitUnifyBlackList /** @internal */ readonly i0: Cause.Cause } /** * @category models * @since 1.0.0 */ export interface ExitUnify extends Effect.EffectUnify { Exit?: () => A[Unify.typeSymbol] extends Exit | infer _ ? Exit : never } /** * @category models * @since 1.0.0 */ export interface ExitUnifyBlackList extends Effect.EffectUnifyBlacklist { Effect?: true } /** * Represents a successful `Effect` workflow and containing the returned value * of type `A`. * * @since 1.0.0 * @category models */ export interface Success extends Effect.Effect, Pipeable, Inspectable { readonly _tag: "Success" readonly value: A [Unify.typeSymbol]?: unknown [Unify.unifySymbol]?: ExitUnify [Unify.blacklistSymbol]?: ExitUnifyBlackList /** @internal */ readonly i0: A } /** * Returns `true` if the specified value is an `Exit`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export const isExit: (u: unknown) => u is Exit = core.exitIsExit /** * Returns `true` if the specified `Exit` is a `Failure`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export const isFailure: (self: Exit) => self is Failure = core.exitIsFailure /** * Returns `true` if the specified `Exit` is a `Success`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export const isSuccess: (self: Exit) => self is Success = core.exitIsSuccess /** * Returns `true` if the specified exit is a `Failure` **and** the `Cause` of * the failure was due to interruption, `false` otherwise. * * @since 1.0.0 * @category getters */ export const isInterrupted: (self: Exit) => boolean = core.exitIsInterrupted /** * Maps the `Success` value of the specified exit to the provided constant * value. * * @since 1.0.0 * @category mapping */ export const as: { (value: A2): (self: Exit) => Exit (self: Exit, value: A2): Exit } = core.exitAs /** * Maps the `Success` value of the specified exit to a void. * * @since 1.0.0 * @category mapping */ export const asUnit: (self: Exit) => Exit = core.exitAsUnit /** * Returns a `Some>` if the specified exit is a `Failure`, `None` * otherwise. * * @since 1.0.0 * @category getters */ export const causeOption: (self: Exit) => Option.Option> = core.exitCauseOption /** * Collects all of the specified exit values into a `Some>>`. If * the provided iterable contains no elements, `None` will be returned. * * @since 1.0.0 * @category constructors */ export const all: ( exits: Iterable>, options?: { readonly parallel?: boolean } | undefined ) => Option.Option>> = core.exitCollectAll /** * Constructs a new `Exit.Failure` from the specified unrecoverable defect. * * @since 1.0.0 * @category constructors */ export const die: (defect: unknown) => Exit = core.exitDie /** * Executes the predicate on the value of the specified exit if it is a * `Success`, otherwise returns `false`. * * @since 1.0.0 * @category elements */ export const exists: { (predicate: Predicate): (self: Exit) => boolean (self: Exit, predicate: Predicate): boolean } = core.exitExists /** * Constructs a new `Exit.Failure` from the specified recoverable error of type * `E`. * * @since 1.0.0 * @category constructors */ export const fail: (error: E) => Exit = core.exitFail /** * Constructs a new `Exit.Failure` from the specified `Cause` of type `E`. * * @since 1.0.0 * @category constructors */ export const failCause: (cause: Cause.Cause) => Exit = core.exitFailCause /** * @since 1.0.0 * @category sequencing */ export const flatMap: { (f: (a: A) => Exit): (self: Exit) => Exit (self: Exit, f: (a: A) => Exit): Exit } = core.exitFlatMap /** * @since 1.0.0 * @category sequencing */ export const flatMapEffect: { ( f: (a: A) => Effect.Effect> ): (self: Exit) => Effect.Effect> ( self: Exit, f: (a: A) => Effect.Effect> ): Effect.Effect> } = core.exitFlatMapEffect /** * @since 1.0.0 * @category sequencing */ export const flatten: (self: Exit>) => Exit = core.exitFlatten /** * @since 1.0.0 * @category traversing */ export const forEachEffect: { (f: (a: A) => Effect.Effect): (self: Exit) => Effect.Effect> (self: Exit, f: (a: A) => Effect.Effect): Effect.Effect> } = core.exitForEachEffect /** * Converts an `Either` into an `Exit`. * * @since 1.0.0 * @category conversions */ export const fromEither: (either: Either.Either) => Exit = core.exitFromEither /** * Converts an `Option` into an `Exit`. * * @since 1.0.0 * @category conversions */ export const fromOption: (option: Option.Option) => Exit = core.exitFromOption /** * Returns the `A` if specified exit is a `Success`, otherwise returns the * alternate `A` value computed from the specified function which receives the * `Cause` of the exit `Failure`. * * @since 1.0.0 * @category getters */ export const getOrElse: { (orElse: (cause: Cause.Cause) => A2): (self: Exit) => A1 | A2 (self: Exit, orElse: (cause: Cause.Cause) => A2): A1 | A2 } = core.exitGetOrElse /** * Constructs a new `Exit.Failure` from the specified `FiberId` indicating that * the `Fiber` running an `Effect` workflow was terminated due to interruption. * * @since 1.0.0 * @category constructors */ export const interrupt: (fiberId: FiberId.FiberId) => Exit = core.exitInterrupt /** * Maps over the `Success` value of the specified exit using the provided * function. * * @since 1.0.0 * @category mapping */ export const map: { (f: (a: A) => B): (self: Exit) => Exit (self: Exit, f: (a: A) => B): Exit } = core.exitMap /** * Maps over the `Success` and `Failure` cases of the specified exit using the * provided functions. * * @since 1.0.0 * @category mapping */ export const mapBoth: { ( options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2 } ): (self: Exit) => Exit ( self: Exit, options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2 } ): Exit } = core.exitMapBoth /** * Maps over the error contained in the `Failure` of the specified exit using * the provided function. * * @since 1.0.0 * @category mapping */ export const mapError: { (f: (e: E) => E2): (self: Exit) => Exit (self: Exit, f: (e: E) => E2): Exit } = core.exitMapError /** * Maps over the `Cause` contained in the `Failure` of the specified exit using * the provided function. * * @since 1.0.0 * @category mapping */ export const mapErrorCause: { (f: (cause: Cause.Cause) => Cause.Cause): (self: Exit) => Exit (self: Exit, f: (cause: Cause.Cause) => Cause.Cause): Exit } = core.exitMapErrorCause /** * @since 1.0.0 * @category folding */ export const match: { ( options: { readonly onFailure: (cause: Cause.Cause) => Z1; readonly onSuccess: (a: A) => Z2 } ): (self: Exit) => Z1 | Z2 ( self: Exit, options: { readonly onFailure: (cause: Cause.Cause) => Z1; readonly onSuccess: (a: A) => Z2 } ): Z1 | Z2 } = core.exitMatch /** * @since 1.0.0 * @category folding */ export const matchEffect: { ( options: { readonly onFailure: (cause: Cause.Cause) => Effect.Effect readonly onSuccess: (a: A) => Effect.Effect } ): (self: Exit) => Effect.Effect ( self: Exit, options: { readonly onFailure: (cause: Cause.Cause) => Effect.Effect readonly onSuccess: (a: A) => Effect.Effect } ): Effect.Effect } = core.exitMatchEffect /** * Constructs a new `Exit.Success` containing the specified value of type `A`. * * @since 1.0.0 * @category constructors */ export const succeed: (value: A) => Exit = core.exitSucceed /** * Represents an `Exit` which succeeds with `undefined`. * * @since 1.0.0 * @category constructors */ export const unit: Exit = core.exitUnit /** * Sequentially zips the this result with the specified result or else returns * the failed `Cause`. * * @since 1.0.0 * @category zipping */ export const zip: { (that: Exit): (self: Exit) => Exit (self: Exit, that: Exit): Exit } = core.exitZip /** * Sequentially zips the this result with the specified result discarding the * second element of the tuple or else returns the failed `Cause`. * * @since 1.0.0 * @category zipping */ export const zipLeft: { (that: Exit): (self: Exit) => Exit (self: Exit, that: Exit): Exit } = core.exitZipLeft /** * Sequentially zips the this result with the specified result discarding the * first element of the tuple or else returns the failed `Cause`. * * @since 1.0.0 * @category zipping */ export const zipRight: { (that: Exit): (self: Exit) => Exit (self: Exit, that: Exit): Exit } = core.exitZipRight /** * Parallelly zips the this result with the specified result or else returns * the failed `Cause`. * * @since 1.0.0 * @category zipping */ export const zipPar: { (that: Exit): (self: Exit) => Exit (self: Exit, that: Exit): Exit } = core.exitZipPar /** * Parallelly zips the this result with the specified result discarding the * second element of the tuple or else returns the failed `Cause`. * * @since 1.0.0 * @category zipping */ export const zipParLeft: { (that: Exit): (self: Exit) => Exit (self: Exit, that: Exit): Exit } = core.exitZipParLeft /** * Parallelly zips the this result with the specified result discarding the * first element of the tuple or else returns the failed `Cause`. * * @since 1.0.0 * @category zipping */ export const zipParRight: { (that: Exit): (self: Exit) => Exit (self: Exit, that: Exit): Exit } = core.exitZipParRight /** * Zips this exit together with that exit using the specified combination * functions. * * @since 1.0.0 * @category zipping */ export const zipWith: { ( that: Exit, options: { readonly onSuccess: (a: A, b: B) => C readonly onFailure: (cause: Cause.Cause, cause2: Cause.Cause) => Cause.Cause } ): (self: Exit) => Exit ( self: Exit, that: Exit, options: { readonly onSuccess: (a: A, b: B) => C readonly onFailure: (cause: Cause.Cause, cause2: Cause.Cause) => Cause.Cause } ): Exit } = core.exitZipWith