<A, E>(self: Exit<A, E>): Result.Result<Failure<never, E>, Success<A>>Extracts the Failure variant from an Exit as a Result.
When to use
Use when composing Exit checks with Filter or other Result-based
filtering APIs and you want the full Failure wrapper.
Details
Returns Result.succeed(failure) when the Exit is a Failure, or
Result.fail(success) with the original Success otherwise.
Gotchas
This is not an Option accessor or an Effect failure. A failed extraction is
represented as data in the Result failure channel.
Example (Filtering for failure)
import { Exit, Result } from "effect"
const exit = Exit.fail("err")
const result = Exit.filterFailure(exit)
console.log(Result.isSuccess(result)) // trueexport const const filterFailure: <A, E>(
self: Exit<A, E>
) => Result.Result<Failure<never, E>, Success<A>>
Extracts the Failure variant from an Exit as a Result.
When to use
Use when composing Exit checks with Filter or other Result-based
filtering APIs and you want the full Failure wrapper.
Details
Returns Result.succeed(failure) when the Exit is a Failure, or
Result.fail(success) with the original Success otherwise.
Gotchas
This is not an Option accessor or an Effect failure. A failed extraction is
represented as data in the Result failure channel.
Example (Filtering for failure)
import { Exit, Result } from "effect"
const exit = Exit.fail("err")
const result = Exit.filterFailure(exit)
console.log(Result.isSuccess(result)) // true
filterFailure: <function (type parameter) A in <A, E>(self: Exit<A, E>): Result.Result<Failure<never, E>, Success<A>>A, function (type parameter) E in <A, E>(self: Exit<A, E>): Result.Result<Failure<never, E>, Success<A>>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>): Result.Result<Failure<never, E>, Success<A>>A, function (type parameter) E in <A, E>(self: Exit<A, E>): Result.Result<Failure<never, E>, Success<A>>E>) => import ResultResult.type Result<A, E = never> = Result.Success<A, E> | Result.Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<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<never, function (type parameter) E in <A, E>(self: Exit<A, E>): Result.Result<Failure<never, E>, Success<A>>E>, interface Success<out A, out E = never>A successful Exit containing a value.
When to use
Use when working with the successful branch of an Exit after narrowing
with
isSuccess
. Access the value via the value property after
narrowing.
Example (Accessing the success value)
import { Exit } from "effect"
const success = Exit.succeed(42)
if (Exit.isSuccess(success)) {
console.log(success._tag) // "Success"
console.log(success.value) // 42
}
Success<function (type parameter) A in <A, E>(self: Exit<A, E>): Result.Result<Failure<never, E>, Success<A>>A>> =
import effecteffect.const exitFilterFailure: <A, E>(
self: Exit.Exit<A, E>
) => Result.Result<
Exit.Failure<never, E>,
Exit.Success<A>
>
exitFilterFailure