<A, E>(self: Exit<A, E>): self is Failure<A, E>Checks whether a failed Exit contains typed errors (Fail reasons).
When to use
Use to distinguish typed failures from defects or interruptions.
Details
Returns false for successful exits. Only checks for Fail reasons in the
Cause. A Cause with only Die or Interrupt reasons returns false.
Example (Checking for typed errors)
import { Exit } from "effect"
console.log(Exit.hasFails(Exit.fail("err"))) // true
console.log(Exit.hasFails(Exit.die(new Error("bug")))) // false
console.log(Exit.hasFails(Exit.succeed(42))) // falseexport const const hasFails: <A, E>(
self: Exit<A, E>
) => self is Failure<A, E>
Checks whether a failed Exit contains typed errors (Fail reasons).
When to use
Use to distinguish typed failures from defects or interruptions.
Details
Returns false for successful exits. Only checks for Fail reasons in the
Cause. A Cause with only Die or Interrupt reasons returns false.
Example (Checking for typed errors)
import { Exit } from "effect"
console.log(Exit.hasFails(Exit.fail("err"))) // true
console.log(Exit.hasFails(Exit.die(new Error("bug")))) // false
console.log(Exit.hasFails(Exit.succeed(42))) // false
hasFails: <function (type parameter) A in <A, E>(self: Exit<A, E>): self is Failure<A, E>A, function (type parameter) E in <A, E>(self: Exit<A, E>): self is Failure<A, E>E>(self: Exit<A, E>self: type Exit<A, E = never> = Success<A, E> | 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<function (type parameter) A in <A, E>(self: Exit<A, E>): self is Failure<A, E>A, function (type parameter) E in <A, E>(self: Exit<A, E>): self is Failure<A, E>E>) => self: Exit<A, E>self is interface Failure<out A, out E>A failed Exit containing a Cause.
When to use
Use when working with the failed branch of an Exit after narrowing with
isFailure
. Access the cause via the cause property after
narrowing.
Details
The Cause<E> may contain typed errors, defects, or interruptions.
Example (Accessing the failure cause)
import { Exit } from "effect"
const failure = Exit.fail("something went wrong")
if (Exit.isFailure(failure)) {
console.log(failure._tag) // "Failure"
console.log(failure.cause) // Cause representing the error
}
Failure<function (type parameter) A in <A, E>(self: Exit<A, E>): self is Failure<A, E>A, function (type parameter) E in <A, E>(self: Exit<A, E>): self is Failure<A, E>E> = import effecteffect.const exitHasFails: <A, E>(
self: Exit.Exit<A, E>
) => self is Exit.Failure<A, E>
exitHasFails