mini-effect
    Preparing search index...

    Function pipe

    • Composes an Effect with one or more pipeable operations into a single sequential effect.

      Type Parameters

      Parameters

      • first: F

        The initial effect whose result seeds the pipeline

      • ...pipeable: PipeReturn<[F, ...P[]]> extends never ? never : P

        One or more pipeable operations to apply in sequence

      Returns PipeReturn<[F, ...P[]]>

      A new Effect representing the entire composed pipeline

      pipe accepts an initial effect followed by any number of pipeable operations — functions that receive the previous result and return a new Effect, WrapEffect error handlers (e.g. from catchSome or catchTags), or dependency providers.

      Operations are executed in order:

      1. Dependency providers (Provide) are applied first, making their values available to all subsequent effects.
      2. Error handlers (WrapEffect) are registered and invoked whenever an error occurs anywhere in the chain.
      3. Transform functions receive the previous success value and must return a new Effect.

      The return type is fully inferred — success, error, and dependency types are threaded through the chain with compile-time safety. A type error is produced if the output type of one step doesn't match the input type of the next.

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

      const result = await run(
      pipe(
      succeed(5),
      (n: number) => succeed(n * 2),
      (n: number) => succeed(n + 1),
      ),
      );
      // => 11
      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"