<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.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<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 ExcludeDone<E> =
E extends Cause.Done<any> ? never : E
Excludes Cause.Done completion signals from an error type union.
When to use
Use to describe the ordinary error type that remains after Cause.Done
completion signals have been handled or filtered out of an error union.
ExcludeDone<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.const map: {
<A, B>(f: (a: A) => B): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E, R>
<A, E, R, B>(
self: Effect<A, E, R>,
f: (a: A) => B
): Effect<B, E, R>
}
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