mini-effect
    Preparing search index...

    Function catchSome

    • Creates a WrapEffect that intercepts errors and optionally recovers.

      Type Parameters

      • T = any

        The success type of the recovery effect

      • C = any

        The error type of the recovery effect

      • CE = any

        The error type(s) handled (caught) by this wrapper

      • D = any

        Dependencies required by the recovery effect

      • P = any

        Dependencies provided by the recovery effect

      Parameters

      • thunk: (cause: unknown) => Effect<T, C, D, P> | undefined

        A function that receives the error cause and returns either a recovery Effect or undefined to let the error pass through

      Returns WrapEffect<T, C, CE, D, P>

      A WrapEffect that can be used in a pipe chain

      The provided handler is called with the thrown cause whenever the preceding effect fails. If the handler returns an Effect, that effect is used as the recovery value. If it returns undefined, the original error propagates unchanged.

      catchSome is typically used inside pipe or Effect.pipe to attach partial error-recovery logic to an effect chain.

      import { fn, pipe, catchSome, succeed, run } from "mini-effect";

      const result = await run(
      pipe(
      fn(() => { throw new Error("x"); }),
      catchSome((cause) =>
      cause instanceof Error ? succeed("recovered") : undefined,
      ),
      ),
      );
      // => "recovered"