mini-effect
    Preparing search index...

    Class Dependency<D, T>

    A typed dependency tag that represents a value effects need at runtime.

    Dependency extends Effect so it can be yielded inside gen generators with yield*. When yielded, it looks up its tag in the internal context and returns the provided value. If the dependency has not been supplied via Dependency.provide, the effect fails with Error("Missing dependency: <tag>").

    Instances are created via the dependency factory rather than by direct construction.

    import { dependency, gen, run } from "mini-effect";

    const Config = dependency("Config")<{ port: number }>();

    const program = gen(function* () {
    const cfg = yield* Config;
    return `Listening on port ${cfg.port}`;
    });

    await run(program.pipe(Config.provide({ port: 3000 })));
    // => "Listening on port 3000"

    Type Parameters

    • D extends string = any

      A string literal type used as the dependency's unique tag

    • T = any

      The type of the value this dependency resolves to

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    __tag: D
    "[DEPENDENCY_TYPE]": Dependency
    "[DEPENDENCY]": true
    "[ERROR]"?: (cause: unknown) => Effect<any, any, any, any> | undefined
    "[PROVIDES_TYPE]": never
    "[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, never, Dependency<D, T>, never>, ...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
    • Creates a Provide effect that supplies a concrete value for this dependency.

      Parameters

      • instance: T

        The concrete value to supply for this dependency

      Returns Provide<D, T>

      A Provide effect that, when included in a pipeline, makes instance available under this dependency's tag

      The returned Provide instance is a Pipeable operation intended for use with pipe or Effect.pipe. When the pipeline executes, the provided value is written into the dependency context so that any yield* of this dependency resolves to instance.

      import { dependency, gen, run } from "mini-effect";

      const Logger = dependency("Logger")<{ log: (msg: string) => void }>();

      const program = gen(function* () {
      const logger = yield* Logger;
      logger.log("hello");
      });

      await run(program.pipe(Logger.provide({ log: console.log })));