<A, E>(input: Exit<A, E>): Result.Result<E, Exit<A, E>>Extracts the first typed error value from a failed Exit as a Result.
When to use
Use when you need the first typed error from an Exit as a Result for
Filter or other Result-based filtering APIs.
Details
Returns Result.succeed(error) when the Cause contains a Fail reason, or
Result.fail(exit) with the original Exit otherwise.
Gotchas
Only finds the first Fail reason. If the Cause has multiple errors, the rest are ignored.
Example (Finding the first typed error)
import { Exit, Result } from "effect"
const exit = Exit.fail("not found")
const result = Exit.findError(exit)
console.log(Result.isSuccess(result) && result.success) // "not found"
const defect = Exit.die(new Error("bug"))
const noError = Exit.findError(defect)
console.log(Result.isFailure(noError)) // trueexport const const findError: <A, E>(
input: Exit<A, E>
) => Result.Result<E, Exit<A, E>>
Extracts the first typed error value from a failed Exit as a Result.
When to use
Use when you need the first typed error from an Exit as a Result for
Filter or other Result-based filtering APIs.
Details
Returns Result.succeed(error) when the Cause contains a Fail reason, or
Result.fail(exit) with the original Exit otherwise.
Gotchas
Only finds the first Fail reason. If the Cause has multiple errors, the rest
are ignored.
Example (Finding the first typed error)
import { Exit, Result } from "effect"
const exit = Exit.fail("not found")
const result = Exit.findError(exit)
console.log(Result.isSuccess(result) && result.success) // "not found"
const defect = Exit.die(new Error("bug"))
const noError = Exit.findError(defect)
console.log(Result.isFailure(noError)) // true
findError: <function (type parameter) A in <A, E>(input: Exit<A, E>): Result.Result<E, Exit<A, E>>A, function (type parameter) E in <A, E>(input: Exit<A, E>): Result.Result<E, Exit<A, E>>E>(input: Exit<A, E>input: 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>(input: Exit<A, E>): Result.Result<E, Exit<A, E>>A, function (type parameter) E in <A, E>(input: Exit<A, E>): Result.Result<E, Exit<A, E>>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<function (type parameter) E in <A, E>(input: Exit<A, E>): Result.Result<E, Exit<A, E>>E, 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>(input: Exit<A, E>): Result.Result<E, Exit<A, E>>A, function (type parameter) E in <A, E>(input: Exit<A, E>): Result.Result<E, Exit<A, E>>E>> = import effecteffect.const exitFindError: <A, E>(
input: Exit<A, E>
) => Result.Result<unknown, Exit<A, E>>
exitFindError