mini-effect
    Preparing search index...

    Class Effect<T, C, D, P>

    The core lazy, composable, cancellable computation type.

    An Effect represents a deferred computation that, when executed via run, produces a success value of type T or fails with an error of type C. Effects are lazy — they do nothing until explicitly run.

    Effects can declare dependencies (type parameter D) that must be satisfied via Dependency.provide before execution, and can provide dependencies to inner effects (type parameter P).

    Effects are iterable, which allows them to be composed with yield* inside gen generator functions. They also expose a pipe method for fluent chaining with Pipeable operations.

    Use the factory functions fn, succeed, fail, and gen to create effects rather than instantiating this class directly.

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

    // Create effects with factory functions
    const fetchUser = fn((signal) => fetch("/user", { signal }).then(r => r.json()));
    const greeting = succeed("hello");

    // Compose with gen
    const program = gen(function* () {
    const user = yield* fetchUser;
    const msg = yield* greeting;
    return `${msg}, ${user.name}`;
    });

    // Execute
    await run(program);

    Type Parameters

    • T = any

      The success value type (what the effect produces on success)

    • C = any

      The error type (what the effect produces on failure)

    • D = any

      The dependencies required by this effect (satisfied via Dependency.provide)

    • P = any

      The dependencies provided by this effect to inner effects

    Hierarchy (View Summary)

    Index

    Constructors

    • Type Parameters

      • T = any

        The success value type (what the effect produces on success)

      • C = any

        The error type (what the effect produces on failure)

      • D = any

        The dependencies required by this effect (satisfied via Dependency.provide)

      • P = any

        The dependencies provided by this effect to inner effects

      Parameters

      • Optionalrun: Thunk<T>
      • OptionalcatchSome: (cause: unknown) => Effect<any, any, any, any> | undefined

      Returns Effect<T, C, D, P>

    Properties

    "[DEPENDENCY_TYPE]": D
    "[ERROR]"?: (cause: unknown) => Effect<any, any, any, any> | undefined
    "[PROVIDES_TYPE]": P
    "[RUN]"?: Thunk<T>

    Methods

    • Composes this effect with one or more Pipeable operations into a single sequential effect.

      Type Parameters

      Parameters

      • ...pipeable: E

        One or more pipeable operations to apply after this effect

      Returns PipeReturn<[Effect<T, C, D, P>, ...E[]]>

      A new Effect representing the composed pipeline

      This is a fluent convenience method equivalent to calling the standalone pipe function with this effect as the first argument. It accepts transform functions, error handlers, and dependency providers.

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

      const result = await run(
      succeed(5).pipe(
      (n: number) => succeed(n * 2),
      (n: number) => succeed(n + 1),
      ),
      );
      // => 11