<A, E, R>(self: Stream<Iterable<A>, E, R>): Stream<A, E, R>Flattens the iterables emitted by this stream into the stream's structure.
Example (Flattening iterable values)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const stream = Stream.make([1, 2], [3, 4]).pipe(Stream.flattenIterable)
const values = yield* Stream.runCollect(stream)
yield* Console.log(values)
})
Effect.runPromise(program)
// Output: [ 1, 2, 3, 4 ]export const const flattenIterable: <A, E, R>(
self: Stream<Iterable<A>, E, R>
) => Stream<A, E, R>
Flattens the iterables emitted by this stream into the stream's structure.
Example (Flattening iterable values)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const stream = Stream.make([1, 2], [3, 4]).pipe(Stream.flattenIterable)
const values = yield* Stream.runCollect(stream)
yield* Console.log(values)
})
Effect.runPromise(program)
// Output: [ 1, 2, 3, 4 ]
flattenIterable = <function (type parameter) A in <A, E, R>(self: Stream<Iterable<A>, E, R>): Stream<A, E, R>A, function (type parameter) E in <A, E, R>(self: Stream<Iterable<A>, E, R>): Stream<A, E, R>E, function (type parameter) R in <A, E, R>(self: Stream<Iterable<A>, E, R>): Stream<A, E, R>R>(self: Stream<Iterable<A>, E, R>(parameter) self: {
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; <…;
}
self: 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<import IterableIterable<function (type parameter) A in <A, E, R>(self: Stream<Iterable<A>, E, R>): Stream<A, E, R>A>, function (type parameter) E in <A, E, R>(self: Stream<Iterable<A>, E, R>): Stream<A, E, R>E, function (type parameter) R in <A, E, R>(self: Stream<Iterable<A>, E, R>): Stream<A, E, R>R>): 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<function (type parameter) A in <A, E, R>(self: Stream<Iterable<A>, E, R>): Stream<A, E, R>A, function (type parameter) E in <A, E, R>(self: Stream<Iterable<A>, E, R>): Stream<A, E, R>E, function (type parameter) R in <A, E, R>(self: Stream<Iterable<A>, E, R>): Stream<A, E, R>R> =>
const flatMap: {
<A, A2, E2, R2>(
f: (a: A) => Stream<A2, E2, R2>,
options?:
| {
readonly concurrency?:
| number
| "unbounded"
| undefined
readonly bufferSize?: number | undefined
}
| undefined
): <E, R>(
self: Stream<A, E, R>
) => Stream<A2, E2 | E, R2 | R>
<A, E, R, A2, E2, R2>(
self: Stream<A, E, R>,
f: (a: A) => Stream<A2, E2, R2>,
options?:
| {
readonly concurrency?:
| number
| "unbounded"
| undefined
readonly bufferSize?: number | undefined
}
| undefined
): Stream<A2, E | E2, R | R2>
}
flatMap(self: Stream<Iterable<A>, E, R>(parameter) self: {
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; <…;
}
self, const fromIterable: <A>(
iterable: Iterable<A>,
options?: {
readonly chunkSize?: number | undefined
}
) => Stream<A>
Creates a new Stream from an iterable collection of values.
Details
chunkSize: Maximum number of values emitted per chunk.
Example (Creating a stream from an iterable)
import { Console, Effect, Stream } from "effect"
const numbers = [1, 2, 3]
const program = Effect.gen(function*() {
const stream = Stream.fromIterable(numbers)
const values = yield* Stream.runCollect(stream)
yield* Console.log(values)
})
Effect.runPromise(program)
// Output: [ 1, 2, 3 ]
fromIterable)