effect-io-ai

Package: effect
Module: Result

Result.orElse

Returns the original Result if it is a Success, otherwise applies that to the error and returns the resulting Result.

When to use

Use when a failure should recover into another Result while keeping successes unchanged.

Details

Example (Recovering from a failure)

import { pipe, Result } from "effect"

const result = pipe(
  Result.fail("primary failed"),
  Result.orElse(() => Result.succeed(99))
)
console.log(result)
// Output: { _tag: "Success", success: 99, ... }

See

Signature

declare const orElse: { <E, A2, E2>(that: (err: E) => Result<A2, E2>): <A>(self: Result<A, E>) => Result<A | A2, E2>; <A, E, A2, E2>(self: Result<A, E>, that: (err: E) => Result<A2, E2>): Result<A | A2, E2>; }

Source

Since v2.0.0