<A, E, R>(effect: Effect.Effect<ReadonlyArray<A>, E, R>): Stream<
A,
Pull.ExcludeDone<E>,
R
>Creates a stream from an effect that produces an array of values.
When to use
Use when the array must be acquired from an Effect before the stream emits, and acquisition services or failures should be part of the stream.
Example (Creating a stream from an effect that produces an array of values)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const stream = Stream.fromArrayEffect(Effect.succeed(["Ada", "Grace"]))
const values = yield* Stream.runCollect(stream)
yield* Console.log(values)
})
Effect.runPromise(program)
// Output: [ "Ada", "Grace" ]export const const fromArrayEffect: <A, E, R>(
effect: Effect.Effect<ReadonlyArray<A>, E, R>
) => Stream<A, Pull.ExcludeDone<E>, R>
Creates a stream from an effect that produces an array of values.
When to use
Use when the array must be acquired from an Effect before the stream emits,
and acquisition services or failures should be part of the stream.
Example (Creating a stream from an effect that produces an array of values)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const stream = Stream.fromArrayEffect(Effect.succeed(["Ada", "Grace"]))
const values = yield* Stream.runCollect(stream)
yield* Console.log(values)
})
Effect.runPromise(program)
// Output: [ "Ada", "Grace" ]
fromArrayEffect = <function (type parameter) A in <A, E, R>(effect: Effect.Effect<ReadonlyArray<A>, E, R>): Stream<A, Pull.ExcludeDone<E>, R>A, function (type parameter) E in <A, E, R>(effect: Effect.Effect<ReadonlyArray<A>, E, R>): Stream<A, Pull.ExcludeDone<E>, R>E, function (type parameter) R in <A, E, R>(effect: Effect.Effect<ReadonlyArray<A>, E, R>): Stream<A, Pull.ExcludeDone<E>, R>R>(
effect: Effect.Effect<ReadonlyArray<A>, 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 ReadonlyArray<T>ReadonlyArray<function (type parameter) A in <A, E, R>(effect: Effect.Effect<ReadonlyArray<A>, E, R>): Stream<A, Pull.ExcludeDone<E>, R>A>, function (type parameter) E in <A, E, R>(effect: Effect.Effect<ReadonlyArray<A>, E, R>): Stream<A, Pull.ExcludeDone<E>, R>E, function (type parameter) R in <A, E, R>(effect: Effect.Effect<ReadonlyArray<A>, E, R>): Stream<A, Pull.ExcludeDone<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>(effect: Effect.Effect<ReadonlyArray<A>, E, R>): Stream<A, Pull.ExcludeDone<E>, R>A, import PullPull.type Pull.ExcludeDone = /*unresolved*/ anyExcludeDone<function (type parameter) E in <A, E, R>(effect: Effect.Effect<ReadonlyArray<A>, E, R>): Stream<A, Pull.ExcludeDone<E>, R>E>, function (type parameter) R in <A, E, R>(effect: Effect.Effect<ReadonlyArray<A>, E, R>): Stream<A, Pull.ExcludeDone<E>, R>R> => 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(import EffectEffect.map(effect: Effect.Effect<ReadonlyArray<A>, 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 fromArray: <A>(
array: ReadonlyArray<A>
) => Stream<A>
Creates a stream from an array of values.
Example (Creating a stream from an array of values)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const stream = Stream.fromArray([1, 2, 3])
const values = yield* Stream.runCollect(stream)
yield* Console.log(values)
})
Effect.runPromise(program)
// Output: [ 1, 2, 3 ]
fromArray)) as any