• Creates a new CatT with an empty context.

    Type Parameters

    • M

    Parameters

    • monad: Monad<M>

      The monad implementation for M.

    Returns CatT<M, Record<string, never>>

    A new CatT.

    Examples

    import { monad as optionMonad, none, some } from "./option.ts";
    import { assertEquals } from "../deps.ts";
    import { doT } from "./cat.ts";

    const optionA = some(1);
    const optionB = some(2);
    const optionC = some(3);

    const computation = doT(optionMonad)
    .addM("a", optionA)
    .addM("b", optionB)
    .addWith("bSquared", ({ b }) => b * b)
    .addM("c", optionC);

    assertEquals(
    computation
    .addMWith("cSqrt", ({ c }) => {
    const sqrt = Math.sqrt(c);
    return Number.isInteger(sqrt) ? some(sqrt) : none();
    })
    .finish(({ bSquared, cSqrt }) => bSquared + cSqrt),
    none(),
    );

    const result = computation.finish(({ a, b, c }) => a + b + c);
    assertEquals(result, some(6));

Generated using TypeDoc