Hyperlinkv0.8.0-beta.28

Exit

Exit.matchconsteffect/Exit.ts:787
<A, E, X1, X2>(options: {
  readonly onSuccess: (a: NoInfer<A>) => X1
  readonly onFailure: (cause: Cause.Cause<NoInfer<E>>) => X2
}): (self: Exit<A, E>) => X1 | X2
<A, E, X1, X2>(
  self: Exit<A, E>,
  options: {
    readonly onSuccess: (a: A) => X1
    readonly onFailure: (cause: Cause.Cause<E>) => X2
  }
): X1 | X2

Pattern matches on an Exit, handling both success and failure cases.

When to use

Use when you need exhaustive handling of both Exit success and failure outcomes.

Details

Calls onSuccess with the value if the Exit is a Success, and calls onFailure with the Cause if the Exit is a Failure.

Example (Matching on an Exit)

import { Exit } from "effect"

const success = Exit.succeed(42)

const result = Exit.match(success, {
  onSuccess: (value) => `Got: ${value}`,
  onFailure: () => "Failed"
})
console.log(result) // "Got: 42"
pattern matchingisSuccessisFailure
Source effect/Exit.ts:78713 lines
export const match: {
  <A, E, X1, X2>(options: {
    readonly onSuccess: (a: NoInfer<A>) => X1
    readonly onFailure: (cause: Cause.Cause<NoInfer<E>>) => X2
  }): (self: Exit<A, E>) => X1 | X2
  <A, E, X1, X2>(
    self: Exit<A, E>,
    options: {
      readonly onSuccess: (a: A) => X1
      readonly onFailure: (cause: Cause.Cause<E>) => X2
    }
  ): X1 | X2
} = effect.exitMatch