/**
* @since 2.0.0
*/
import type * as Cause from "./Cause.js"
import type * as Effect from "./Effect.js"
import type * as Either from "./Either.js"
import type * as FiberId from "./FiberId.js"
import type { Inspectable } from "./Inspectable.js"
import * as core from "./internal/core.js"
import type * as Option from "./Option.js"
import type { Pipeable } from "./Pipeable.js"
import type { Predicate, Refinement } from "./Predicate.js"
import type { NoInfer } from "./Types.js"
import type * as Unify from "./Unify.js"
/**
* 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 2.0.0
* @category models
*/
export type Exit = Success | Failure
/**
* Represents a failed `Effect` workflow containing the `Cause` of the failure
* of type `E`.
*
* @since 2.0.0
* @category models
*/
export interface Failure extends Effect.Effect, Pipeable, Inspectable {
readonly _tag: "Failure"
readonly _op: "Failure"
readonly cause: Cause.Cause
[Unify.typeSymbol]?: unknown
[Unify.unifySymbol]?: ExitUnify
[Unify.ignoreSymbol]?: ExitUnifyIgnore
/** @internal */
readonly effect_instruction_i0: Cause.Cause
}
/**
* @category models
* @since 2.0.0
*/
export interface ExitUnify extends Effect.EffectUnify {
Exit?: () => A[Unify.typeSymbol] extends Exit | infer _ ? Exit : never
}
/**
* @category models
* @since 2.0.0
*/
export interface ExitUnifyIgnore extends Effect.EffectUnifyIgnore {
Effect?: true
}
/**
* Represents a successful `Effect` workflow and containing the returned value
* of type `A`.
*
* @since 2.0.0
* @category models
*/
export interface Success extends Effect.Effect, Pipeable, Inspectable {
readonly _tag: "Success"
readonly _op: "Success"
readonly value: A
[Unify.typeSymbol]?: unknown
[Unify.unifySymbol]?: ExitUnify
[Unify.ignoreSymbol]?: ExitUnifyIgnore
/** @internal */
readonly effect_instruction_i0: A
}
/**
* Returns `true` if the specified value is an `Exit`, `false` otherwise.
*
* @since 2.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 2.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 2.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 2.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 2.0.0
* @category mapping
*/
export const as: {
/**
* Maps the `Success` value of the specified exit to the provided constant
* value.
*
* @since 2.0.0
* @category mapping
*/
(value: A2): (self: Exit) => Exit
/**
* Maps the `Success` value of the specified exit to the provided constant
* value.
*
* @since 2.0.0
* @category mapping
*/
(self: Exit, value: A2): Exit
} = core.exitAs
/**
* Maps the `Success` value of the specified exit to a void.
*
* @since 2.0.0
* @category mapping
*/
export const asVoid: (self: Exit) => Exit = core.exitAsVoid
/**
* Returns a `Some>` if the specified exit is a `Failure`, `None`
* otherwise.
*
* @since 2.0.0
* @category getters
*/
export const causeOption: (self: Exit) => Option.Option> = core.exitCauseOption
/**
* Collects all of the specified exit values into a `Some, E>>`. If
* the provided iterable contains no elements, `None` will be returned.
*
* @since 2.0.0
* @category constructors
*/
export const all: (
exits: Iterable>,
options?: { readonly parallel?: boolean | undefined } | undefined
) => Option.Option, E>> = core.exitCollectAll
/**
* Constructs a new `Exit.Failure` from the specified unrecoverable defect.
*
* @since 2.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 2.0.0
* @category elements
*/
export const exists: {
/**
* Executes the predicate on the value of the specified exit if it is a
* `Success`, otherwise returns `false`.
*
* @since 2.0.0
* @category elements
*/
(refinement: Refinement, B>): (self: Exit) => self is Exit
/**
* Executes the predicate on the value of the specified exit if it is a
* `Success`, otherwise returns `false`.
*
* @since 2.0.0
* @category elements
*/
(predicate: Predicate>): (self: Exit) => boolean
/**
* Executes the predicate on the value of the specified exit if it is a
* `Success`, otherwise returns `false`.
*
* @since 2.0.0
* @category elements
*/
(self: Exit, refinement: Refinement): self is Exit
/**
* Executes the predicate on the value of the specified exit if it is a
* `Success`, otherwise returns `false`.
*
* @since 2.0.0
* @category elements
*/
(self: Exit, predicate: Predicate): boolean
} = core.exitExists
/**
* Constructs a new `Exit.Failure` from the specified recoverable error of type
* `E`.
*
* @since 2.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 2.0.0
* @category constructors
*/
export const failCause: (cause: Cause.Cause) => Exit = core.exitFailCause
/**
* @since 2.0.0
* @category sequencing
*/
export const flatMap: {
/**
* @since 2.0.0
* @category sequencing
*/
(f: (a: A) => Exit): (self: Exit) => Exit
/**
* @since 2.0.0
* @category sequencing
*/
(self: Exit, f: (a: A) => Exit): Exit
} = core.exitFlatMap
/**
* @since 2.0.0
* @category sequencing
*/
export const flatMapEffect: {
/**
* @since 2.0.0
* @category sequencing
*/
(f: (a: A) => Effect.Effect, E2, R>): (self: Exit) => Effect.Effect, E2, R>
/**
* @since 2.0.0
* @category sequencing
*/
(self: Exit, f: (a: A) => Effect.Effect, E2, R>): Effect.Effect, E2, R>
} = core.exitFlatMapEffect
/**
* @since 2.0.0
* @category sequencing
*/
export const flatten: (self: Exit, E2>) => Exit = core.exitFlatten
/**
* @since 2.0.0
* @category traversing
*/
export const forEachEffect: {
/**
* @since 2.0.0
* @category traversing
*/
(f: (a: A) => Effect.Effect): (self: Exit) => Effect.Effect, never, R>
/**
* @since 2.0.0
* @category traversing
*/
(self: Exit, f: (a: A) => Effect.Effect): Effect.Effect, never, R>
} = core.exitForEachEffect
/**
* Converts an `Either` into an `Exit`.
*
* @since 2.0.0
* @category conversions
*/
export const fromEither: (either: Either.Either) => Exit = core.exitFromEither
/**
* Converts an `Option` into an `Exit`.
*
* @since 2.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 2.0.0
* @category getters
*/
export const 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` of the exit `Failure`.
*
* @since 2.0.0
* @category getters
*/
(orElse: (cause: Cause.Cause) => A2): (self: Exit) => A2 | A
/**
* 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 2.0.0
* @category getters
*/
(self: Exit, orElse: (cause: Cause.Cause) => A2): A | 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 2.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 2.0.0
* @category mapping
*/
export const map: {
/**
* Maps over the `Success` value of the specified exit using the provided
* function.
*
* @since 2.0.0
* @category mapping
*/
(f: (a: A) => B): (self: Exit) => Exit
/**
* Maps over the `Success` value of the specified exit using the provided
* function.
*
* @since 2.0.0
* @category mapping
*/
(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 2.0.0
* @category mapping
*/
export const mapBoth: {
/**
* Maps over the `Success` and `Failure` cases of the specified exit using the
* provided functions.
*
* @since 2.0.0
* @category mapping
*/
(
options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2 }
): (self: Exit) => Exit
/**
* Maps over the `Success` and `Failure` cases of the specified exit using the
* provided functions.
*
* @since 2.0.0
* @category mapping
*/
(
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 2.0.0
* @category mapping
*/
export const mapError: {
/**
* Maps over the error contained in the `Failure` of the specified exit using
* the provided function.
*
* @since 2.0.0
* @category mapping
*/
(f: (e: E) => E2): (self: Exit) => Exit
/**
* Maps over the error contained in the `Failure` of the specified exit using
* the provided function.
*
* @since 2.0.0
* @category mapping
*/
(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 2.0.0
* @category mapping
*/
export const mapErrorCause: {
/**
* Maps over the `Cause` contained in the `Failure` of the specified exit using
* the provided function.
*
* @since 2.0.0
* @category mapping
*/
(f: (cause: Cause.Cause) => Cause.Cause): (self: Exit) => Exit
/**
* Maps over the `Cause` contained in the `Failure` of the specified exit using
* the provided function.
*
* @since 2.0.0
* @category mapping
*/
(self: Exit, f: (cause: Cause.Cause) => Cause.Cause): Exit
} = core.exitMapErrorCause
/**
* @since 2.0.0
* @category folding
*/
export const match: {
/**
* @since 2.0.0
* @category folding
*/
(
options: { readonly onFailure: (cause: Cause.Cause) => Z1; readonly onSuccess: (a: A) => Z2 }
): (self: Exit) => Z1 | Z2
/**
* @since 2.0.0
* @category folding
*/
(
self: Exit,
options: { readonly onFailure: (cause: Cause.Cause) => Z1; readonly onSuccess: (a: A) => Z2 }
): Z1 | Z2
} = core.exitMatch
/**
* @since 2.0.0
* @category folding
*/
export const matchEffect: {
/**
* @since 2.0.0
* @category folding
*/
(
options: {
readonly onFailure: (cause: Cause.Cause) => Effect.Effect
readonly onSuccess: (a: A) => Effect.Effect
}
): (self: Exit) => Effect.Effect
/**
* @since 2.0.0
* @category folding
*/
(
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 2.0.0
* @category constructors
*/
export const succeed: (value: A) => Exit = core.exitSucceed
const void_: Exit = core.exitVoid
export {
/**
* Represents an `Exit` which succeeds with `undefined`.
*
* @since 2.0.0
* @category constructors
*/
void_ as void
}
/**
* Sequentially zips the this result with the specified result or else returns
* the failed `Cause`.
*
* @since 2.0.0
* @category zipping
*/
export const zip: {
/**
* Sequentially zips the this result with the specified result or else returns
* the failed `Cause`.
*
* @since 2.0.0
* @category zipping
*/
(that: Exit): (self: Exit) => Exit<[A, A2], E2 | E>
/**
* Sequentially zips the this result with the specified result or else returns
* the failed `Cause`.
*
* @since 2.0.0
* @category zipping
*/
(self: Exit, that: Exit): Exit<[A, A2], E | E2>
} = 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 2.0.0
* @category zipping
*/
export const zipLeft: {
/**
* Sequentially zips the this result with the specified result discarding the
* second element of the tuple or else returns the failed `Cause`.
*
* @since 2.0.0
* @category zipping
*/
(that: Exit): (self: Exit) => Exit
/**
* Sequentially zips the this result with the specified result discarding the
* second element of the tuple or else returns the failed `Cause`.
*
* @since 2.0.0
* @category zipping
*/
(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 2.0.0
* @category zipping
*/
export const zipRight: {
/**
* Sequentially zips the this result with the specified result discarding the
* first element of the tuple or else returns the failed `Cause`.
*
* @since 2.0.0
* @category zipping
*/
(that: Exit): (self: Exit) => Exit
/**
* Sequentially zips the this result with the specified result discarding the
* first element of the tuple or else returns the failed `Cause`.
*
* @since 2.0.0
* @category zipping
*/
(self: Exit, that: Exit): Exit
} = core.exitZipRight
/**
* Parallelly zips the this result with the specified result or else returns
* the failed `Cause`.
*
* @since 2.0.0
* @category zipping
*/
export const zipPar: {
/**
* Parallelly zips the this result with the specified result or else returns
* the failed `Cause`.
*
* @since 2.0.0
* @category zipping
*/
(that: Exit): (self: Exit) => Exit<[A, A2], E2 | E>
/**
* Parallelly zips the this result with the specified result or else returns
* the failed `Cause`.
*
* @since 2.0.0
* @category zipping
*/
(self: Exit, that: Exit): Exit<[A, A2], E | E2>
} = 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 2.0.0
* @category zipping
*/
export const zipParLeft: {
/**
* Parallelly zips the this result with the specified result discarding the
* second element of the tuple or else returns the failed `Cause`.
*
* @since 2.0.0
* @category zipping
*/
(that: Exit): (self: Exit) => Exit
/**
* Parallelly zips the this result with the specified result discarding the
* second element of the tuple or else returns the failed `Cause`.
*
* @since 2.0.0
* @category zipping
*/
(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 2.0.0
* @category zipping
*/
export const zipParRight: {
/**
* Parallelly zips the this result with the specified result discarding the
* first element of the tuple or else returns the failed `Cause`.
*
* @since 2.0.0
* @category zipping
*/
(that: Exit): (self: Exit) => Exit
/**
* Parallelly zips the this result with the specified result discarding the
* first element of the tuple or else returns the failed `Cause`.
*
* @since 2.0.0
* @category zipping
*/
(self: Exit, that: Exit): Exit
} = core.exitZipParRight
/**
* Zips this exit together with that exit using the specified combination
* functions.
*
* @since 2.0.0
* @category zipping
*/
export const zipWith: {
/**
* Zips this exit together with that exit using the specified combination
* functions.
*
* @since 2.0.0
* @category zipping
*/
(
that: Exit,
options: {
readonly onSuccess: (a: A, b: B) => C
readonly onFailure: (cause: Cause.Cause, cause2: Cause.Cause) => Cause.Cause
}
): (self: Exit) => Exit
/**
* Zips this exit together with that exit using the specified combination
* functions.
*
* @since 2.0.0
* @category zipping
*/
(
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