Stream<{}, never, never>Provides the entry point for do-notation style stream composition.
Example (Starting stream do notation)
import { Console, Effect, pipe, Stream } from "effect"
const program = pipe(
Stream.Do,
Stream.bind("value", () => Stream.fromArray([1, 2])),
Stream.let("next", ({ value }) => value + 1)
)
const effect = Effect.gen(function*() {
const collected = yield* Stream.runCollect(program)
yield* Console.log(collected)
})
Effect.runPromise(effect)
//=> [{ value: 1, next: 2 }, { value: 2, next: 3 }]do notation
Source effect/Stream.ts:103781 lines
export const const Do: Stream<{}>const Do: {
channel: Channel.Channel<Arr.NonEmptyReadonlyArray<A>, E, void, unknown, unknown, unknown, R>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Provides the entry point for do-notation style stream composition.
Example (Starting stream do notation)
import { Console, Effect, pipe, Stream } from "effect"
const program = pipe(
Stream.Do,
Stream.bind("value", () => Stream.fromArray([1, 2])),
Stream.let("next", ({ value }) => value + 1)
)
const effect = Effect.gen(function*() {
const collected = yield* Stream.runCollect(program)
yield* Console.log(collected)
})
Effect.runPromise(effect)
//=> [{ value: 1, next: 2 }, { value: 2, next: 3 }]
Do: interface Stream<out A, out E = never, out R = never>A Stream<A, E, R> describes a program that can emit many A values, fail
with E, and require R.
Details
Streams are pull-based with backpressure and emit chunks to amortize effect
evaluation. They support monadic composition and error handling similar to
Effect, adapted for multiple values.
Example (Creating and consuming streams)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.make(1, 2, 3).pipe(
Stream.map((n) => n * 2),
Stream.runForEach((n) => Console.log(n))
)
})
Effect.runPromise(program)
// Output:
// 2
// 4
// 6
Stream<{}> = const succeed: <A>(value: A) => Stream<A>Creates a single-valued pure stream.
Example (Creating a single-valued pure stream)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const values = yield* Stream.succeed(3).pipe(Stream.runCollect)
yield* Console.log(values)
})
Effect.runPromise(program)
// [ 3 ]
succeed({})