A new CatT.
const { monad: optionMonad, none, some } = await import("./option.js");
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);
expect(
computation
.addMWith("cSqrt", ({ c }) => {
const sqrt = Math.sqrt(c);
return Number.isInteger(sqrt) ? some(sqrt) : none();
})
.finish(({ bSquared, cSqrt }) => bSquared + cSqrt),
).toStrictEqual(
none(),
);
const result = computation.finish(({ a, b, c }) => a + b + c);
expect(result).toStrictEqual(some(6));
Creates a new
CatTwith an empty context.