Package: effect
Module: Stream
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 Stream 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 { Chunk, Effect, pipe, Stream } from "effect"
const result = pipe(
Stream.Do,
Stream.bind("x", () => Stream.succeed(2)),
Stream.bind("y", () => Stream.succeed(3)),
Stream.let("sum", ({ x, y }) => x + y)
)
assert.deepStrictEqual(Effect.runSync(Stream.runCollect(result)), Chunk.of({ x: 2, y: 3, sum: 5 }))
See
bindTobindbindEffectletSignature
declare const Do: Stream<{}, never, never>
Since v2.0.0