<E>(cause: Cause.Cause<E>): Exit.Exit<
Cause.Done.Extract<E>,
ExcludeDone<E>
>Converts a Cause into an Exit, treating Cause.Done as successful
completion.
When to use
Use to produce an Exit for finalizing a low-level pull workflow when a
Cause.Done signal should be treated as success and any remaining cause
should fail.
Details
If the cause contains a done value, that leftover becomes the successful value. Otherwise the non-done cause becomes the failure cause.
export const const doneExitFromCause: <E>(
cause: Cause.Cause<E>
) => Exit.Exit<
Cause.Done.Extract<E>,
ExcludeDone<E>
>
Converts a Cause into an Exit, treating Cause.Done as successful
completion.
When to use
Use to produce an Exit for finalizing a low-level pull workflow when a
Cause.Done signal should be treated as success and any remaining cause
should fail.
Details
If the cause contains a done value, that leftover becomes the successful
value. Otherwise the non-done cause becomes the failure cause.
doneExitFromCause = <function (type parameter) E in <E>(cause: Cause.Cause<E>): Exit.Exit<Cause.Done.Extract<E>, ExcludeDone<E>>E>(cause: Cause.Cause<E>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
cause: import CauseCause.interface Cause<out E>A structured representation of how an Effect failed.
When to use
Use to preserve the full structured failure information for an effect instead
of collapsing it to a single error value.
Details
Access the individual failure entries through the reasons array, then
narrow each entry with
isFailReason
,
isDieReason
, or
- Use
hasFails
/
hasDies
/
hasInterrupts
to test
for the presence of specific reason kinds without iterating.
- Use
findError
/
findDefect
to extract the first value
of a given kind.
- Use
combine
to merge two causes.
Cause implements Equal — two causes with the same reasons (by value)
compare as equal.
Example (Creating and inspecting a cause)
import { Cause } from "effect"
const cause = Cause.fail("Something went wrong")
console.log(cause.reasons.length) // 1
console.log(Cause.isFailReason(cause.reasons[0])) // true
Companion namespace for the Cause interface.
Cause<function (type parameter) E in <E>(cause: Cause.Cause<E>): Exit.Exit<Cause.Done.Extract<E>, ExcludeDone<E>>E>): import ExitExit.type Exit<A, E = never> = Exit.Success<A, E> | Exit.Failure<A, E>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.
Example (Pattern matching on an Exit)
import { Exit } from "effect"
const success: Exit.Exit<number> = Exit.succeed(42)
const failure: Exit.Exit<number, string> = Exit.fail("error")
const result = Exit.match(success, {
onSuccess: (value) => `Got value: ${value}`,
onFailure: (cause) => `Got error: ${cause}`
})
Namespace containing helper types shared by Exit values.
When to use
Use to reference helper types that describe the shared structure of Exit
values.
Exit<import CauseCause.Done.type Done<A = void>.Extract<E> = E extends Cause.Done<infer L> ? L : neverExtracts the value type A from a Done<A> that may be nested in an
error union.
Extract<function (type parameter) E in <E>(cause: Cause.Cause<E>): Exit.Exit<Cause.Done.Extract<E>, ExcludeDone<E>>E>, type ExcludeDone<E> =
E extends Cause.Done<any> ? never : E
Excludes Cause.Done completion signals from an error type union.
When to use
Use to describe the ordinary error type that remains after Cause.Done
completion signals have been handled or filtered out of an error union.
ExcludeDone<function (type parameter) E in <E>(cause: Cause.Cause<E>): Exit.Exit<Cause.Done.Extract<E>, ExcludeDone<E>>E>> => {
const const halt: Result.Result<
Cause.Done.Only<E>,
Cause.Cause<Exclude<E, Cause.Done<any>>>
>
halt = const filterDone: <E>(
input: Cause.Cause<E>
) => Result.Result<
Cause.Done.Only<E>,
Cause.Cause<ExcludeDone<E>>
>
Finds a Cause.Done failure in a Cause.
When to use
Use to separate Cause.Done completion from ordinary causes while preserving
the typed done value.
Details
Returns a successful Result with the Cause.Done value when one is
present, otherwise returns a failed Result containing the non-done cause.
filterDone(cause: Cause.Cause<E>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
cause)
return !import ResultResult.const isFailure: <A, E>(
self: Result<A, E>
) => self is Failure<A, E>
Checks whether a Result is a Failure.
When to use
Use to narrow a known Result to the Failure variant.
Details
- Acts as a TypeScript type guard, narrowing to
Failure<A, E>
- After narrowing, you can access
.failure to read the error value
Example (Narrowing to failure)
import { Result } from "effect"
const result = Result.fail("oops")
if (Result.isFailure(result)) {
console.log(result.failure)
// Output: "oops"
}
isFailure(const halt: Result.Result<
Cause.Done.Only<E>,
Cause.Cause<Exclude<E, Cause.Done<any>>>
>
halt) ? import ExitExit.const succeed: <A>(a: A) => Exit<A>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.
Example (Creating a successful Exit)
import { Exit } from "effect"
const exit = Exit.succeed(42)
console.log(Exit.isSuccess(exit)) // true
succeed(const halt: Result.Success<
Cause.Done.Only<E>,
Cause.Cause<Exclude<E, Cause.Done<any>>>
>
const halt: {
_tag: "Success";
_op: "Success";
success: A;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
halt.Success<Done<A = void>.Only<E>, Cause<Exclude<E, Done<any>>>>.success: Cause.Done.Only<E>success.Done<unknown>.value: unknownvalue as any) : import ExitExit.const failCause: <E>(
cause: Cause.Cause<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.
Example (Creating a failed Exit from a Cause)
import { Cause, Exit } from "effect"
const cause = Cause.fail("Something went wrong")
const exit = Exit.failCause(cause)
console.log(Exit.isFailure(exit)) // true
failCause(const halt: Result.Failure<
Cause.Done.Only<E>,
Cause.Cause<Exclude<E, Cause.Done<any>>>
>
const halt: {
_tag: "Failure";
_op: "Failure";
failure: E;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
halt.Failure<Done<A = void>.Only<E>, Cause<Exclude<E, Done<any>>>>.failure: Cause.Cause<Exclude<E, Cause.Done<any>>>(property) Failure<Done<A = void>.Only<E>, Cause<Exclude<E, Done<any>>>>.failure: {
reasons: ReadonlyArray<Reason<E>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
failure)
}