Package: effect
Module: Effect
The “do simulation” in Effect allows you to write code in a more declarative style, similar to the “do notation” in other programming languages. It provides a way to define variables and perform operations on them using functions like bind and let.
Here’s how the do simulation works:
Do valuebind function to define variables and bind them to Effect valuesbind statements to define multiple variables within the scopelet function to define variables and bind them to simple valuesExample
import * as assert from "node:assert"
import { Effect, pipe } from "effect"
const result = pipe(
Effect.Do,
Effect.bind("x", () => Effect.succeed(2)),
Effect.bind("y", () => Effect.succeed(3)),
Effect.let("sum", ({ x, y }) => x + y)
)
assert.deepStrictEqual(Effect.runSync(result), { x: 2, y: 3, sum: 5 })
See
DobindletSignature
declare const bindTo: { <N extends string>(name: N): <A, E, R>(self: Effect<A, E, R>) => Effect<{ [K in N]: A; }, E, R>; <A, E, R, N extends string>(self: Effect<A, E, R>, name: N): Effect<{ [K in N]: A; }, E, R>; }
Since v2.0.0