<A, E2, R2, E, R>(effect: Effect.Effect<Stream<A, E2, R2>, E, R>): Stream<
A,
E | E2,
R2 | Exclude<R, Scope.Scope>
>Creates a stream produced from an Effect.
Example (Unwrapping a stream effect)
import { Console, Effect, Stream } from "effect"
const effect = Effect.succeed(Stream.make(1, 2, 3))
const stream = Stream.unwrap(effect)
const program = Effect.gen(function*() {
const chunk = yield* Stream.runCollect(stream)
yield* Console.log(chunk)
})
// [1, 2, 3]export const const unwrap: <A, E2, R2, E, R>(
effect: Effect.Effect<Stream<A, E2, R2>, E, R>
) => Stream<
A,
E | E2,
R2 | Exclude<R, Scope.Scope>
>
Creates a stream produced from an Effect.
Example (Unwrapping a stream effect)
import { Console, Effect, Stream } from "effect"
const effect = Effect.succeed(Stream.make(1, 2, 3))
const stream = Stream.unwrap(effect)
const program = Effect.gen(function*() {
const chunk = yield* Stream.runCollect(stream)
yield* Console.log(chunk)
})
// [1, 2, 3]
unwrap = <function (type parameter) A in <A, E2, R2, E, R>(effect: Effect.Effect<Stream<A, E2, R2>, E, R>): Stream<A, E | E2, R2 | Exclude<R, Scope.Scope>>A, function (type parameter) E2 in <A, E2, R2, E, R>(effect: Effect.Effect<Stream<A, E2, R2>, E, R>): Stream<A, E | E2, R2 | Exclude<R, Scope.Scope>>E2, function (type parameter) R2 in <A, E2, R2, E, R>(effect: Effect.Effect<Stream<A, E2, R2>, E, R>): Stream<A, E | E2, R2 | Exclude<R, Scope.Scope>>R2, function (type parameter) E in <A, E2, R2, E, R>(effect: Effect.Effect<Stream<A, E2, R2>, E, R>): Stream<A, E | E2, R2 | Exclude<R, Scope.Scope>>E, function (type parameter) R in <A, E2, R2, E, R>(effect: Effect.Effect<Stream<A, E2, R2>, E, R>): Stream<A, E | E2, R2 | Exclude<R, Scope.Scope>>R>(
effect: Effect.Effect<Stream<A, E2, R2>, E, R>(parameter) effect: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
effect: import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<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, E2, R2, E, R>(effect: Effect.Effect<Stream<A, E2, R2>, E, R>): Stream<A, E | E2, R2 | Exclude<R, Scope.Scope>>A, function (type parameter) E2 in <A, E2, R2, E, R>(effect: Effect.Effect<Stream<A, E2, R2>, E, R>): Stream<A, E | E2, R2 | Exclude<R, Scope.Scope>>E2, function (type parameter) R2 in <A, E2, R2, E, R>(effect: Effect.Effect<Stream<A, E2, R2>, E, R>): Stream<A, E | E2, R2 | Exclude<R, Scope.Scope>>R2>, function (type parameter) E in <A, E2, R2, E, R>(effect: Effect.Effect<Stream<A, E2, R2>, E, R>): Stream<A, E | E2, R2 | Exclude<R, Scope.Scope>>E, function (type parameter) R in <A, E2, R2, E, R>(effect: Effect.Effect<Stream<A, E2, R2>, E, R>): Stream<A, E | E2, R2 | Exclude<R, Scope.Scope>>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, E2, R2, E, R>(effect: Effect.Effect<Stream<A, E2, R2>, E, R>): Stream<A, E | E2, R2 | Exclude<R, Scope.Scope>>A, function (type parameter) E in <A, E2, R2, E, R>(effect: Effect.Effect<Stream<A, E2, R2>, E, R>): Stream<A, E | E2, R2 | Exclude<R, Scope.Scope>>E | function (type parameter) E2 in <A, E2, R2, E, R>(effect: Effect.Effect<Stream<A, E2, R2>, E, R>): Stream<A, E | E2, R2 | Exclude<R, Scope.Scope>>E2, function (type parameter) R2 in <A, E2, R2, E, R>(effect: Effect.Effect<Stream<A, E2, R2>, E, R>): Stream<A, E | E2, R2 | Exclude<R, Scope.Scope>>R2 | type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<function (type parameter) R in <A, E2, R2, E, R>(effect: Effect.Effect<Stream<A, E2, R2>, E, R>): Stream<A, E | E2, R2 | Exclude<R, Scope.Scope>>R, import ScopeScope.type Scope.Scope = /*unresolved*/ anyScope>> => const fromChannel: <
Arr extends Arr.NonEmptyReadonlyArray<any>,
E,
R
>(
channel: Channel.Channel<
Arr,
E,
void,
unknown,
unknown,
unknown,
R
>
) => Stream<
Arr extends Arr.NonEmptyReadonlyArray<infer A>
? A
: never,
E,
R
>
Creates a stream from a array-emitting Channel.
Example (Creating a stream from an array-emitting channel)
import { Channel, Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const channel = Channel.succeed([1, 2, 3] as const)
const stream = Stream.fromChannel(channel)
const result = yield* Stream.runCollect(stream)
yield* Console.log(result)
})
// Output: [ 1, 2, 3 ]
fromChannel(import ChannelChannel.unwrap(import EffectEffect.map(effect: Effect.Effect<Stream<A, E2, R2>, E, R>(parameter) effect: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
effect, const toChannel: <A, E, R>(
stream: Stream<A, E, R>
) => Channel.Channel<
Arr.NonEmptyReadonlyArray<A>,
E,
void,
unknown,
unknown,
unknown,
R
>
Creates a channel from a stream.
Example (Converting a stream to a channel)
import { Channel, Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const stream = Stream.make(1, 2, 3)
const channel = Stream.toChannel(stream)
const values = yield* Channel.runCollect(channel)
yield* Console.log(values.flat())
})
Effect.runPromise(program)
// Output: [ 1, 2, 3 ]
toChannel)))