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