<Input, R2, Provides, PolicyE>(
policy: ExecutionPlan.ExecutionPlan<{
provides: Provides
input: Input
error: PolicyE
requirements: R2
}>,
options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined
}
): <A, E extends Input, R>(
self: Stream<A, E, R>
) => Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
<A, E extends Input, R, R2, Input, Provides, PolicyE>(
self: Stream<A, E, R>,
policy: ExecutionPlan.ExecutionPlan<{
provides: Provides
input: Input
error: PolicyE
requirements: R2
}>,
options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined
}
): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>Applies an ExecutionPlan to a stream, retrying with step-provided resources
until it succeeds or the plan is exhausted.
Details
By default, a failing step can fallback even after emitting elements; set
preventFallbackOnPartialStream to fail instead of mixing partial output with
a later fallback.
Example (Applying an execution plan)
import { Console, Context, Effect, ExecutionPlan, Layer, Stream } from "effect"
class Service extends Context.Service<Service>()("Service", {
make: Effect.succeed({
stream: Stream.fail("A") as Stream.Stream<number, string>
})
}) {
static Bad = Layer.succeed(Service, Service.of({ stream: Stream.fail("A") }))
static Good = Layer.succeed(Service, Service.of({ stream: Stream.make(1, 2, 3) }))
}
const plan = ExecutionPlan.make(
{ provide: Service.Bad },
{ provide: Service.Good }
)
const stream = Stream.unwrap(Effect.map(Service, (_) => _.stream))
const program = Effect.gen(function*() {
const items = yield* stream.pipe(Stream.withExecutionPlan(plan), Stream.runCollect)
yield* Console.log(items)
})
Effect.runPromise(program)
// Output: [ 1, 2, 3 ]export const const withExecutionPlan: {
<Input, R2, Provides, PolicyE>(
policy: ExecutionPlan.ExecutionPlan<{
provides: Provides
input: Input
error: PolicyE
requirements: R2
}>,
options?: {
readonly preventFallbackOnPartialStream?:
| boolean
| undefined
}
): <A, E extends Input, R>(
self: Stream<A, E, R>
) => Stream<
A,
E | PolicyE,
R2 | Exclude<R, Provides>
>
<
A,
E extends Input,
R,
R2,
Input,
Provides,
PolicyE
>(
self: Stream<A, E, R>,
policy: ExecutionPlan.ExecutionPlan<{
provides: Provides
input: Input
error: PolicyE
requirements: R2
}>,
options?: {
readonly preventFallbackOnPartialStream?:
| boolean
| undefined
}
): Stream<
A,
E | PolicyE,
R2 | Exclude<R, Provides>
>
}
Applies an ExecutionPlan to a stream, retrying with step-provided resources
until it succeeds or the plan is exhausted.
Details
By default, a failing step can fallback even after emitting elements; set
preventFallbackOnPartialStream to fail instead of mixing partial output with
a later fallback.
Example (Applying an execution plan)
import { Console, Context, Effect, ExecutionPlan, Layer, Stream } from "effect"
class Service extends Context.Service<Service>()("Service", {
make: Effect.succeed({
stream: Stream.fail("A") as Stream.Stream<number, string>
})
}) {
static Bad = Layer.succeed(Service, Service.of({ stream: Stream.fail("A") }))
static Good = Layer.succeed(Service, Service.of({ stream: Stream.make(1, 2, 3) }))
}
const plan = ExecutionPlan.make(
{ provide: Service.Bad },
{ provide: Service.Good }
)
const stream = Stream.unwrap(Effect.map(Service, (_) => _.stream))
const program = Effect.gen(function*() {
const items = yield* stream.pipe(Stream.withExecutionPlan(plan), Stream.runCollect)
yield* Console.log(items)
})
Effect.runPromise(program)
// Output: [ 1, 2, 3 ]
withExecutionPlan: {
<function (type parameter) Input in <Input, R2, Provides, PolicyE>(policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): <A, E extends Input, R>(self: Stream<A, E, R>) => Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Input, function (type parameter) R2 in <Input, R2, Provides, PolicyE>(policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): <A, E extends Input, R>(self: Stream<A, E, R>) => Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
R2, function (type parameter) Provides in <Input, R2, Provides, PolicyE>(policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): <A, E extends Input, R>(self: Stream<A, E, R>) => Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Provides, function (type parameter) PolicyE in <Input, R2, Provides, PolicyE>(policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): <A, E extends Input, R>(self: Stream<A, E, R>) => Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
PolicyE>(
policy: ExecutionPlan.ExecutionPlan<{
provides: Provides
input: Input
error: PolicyE
requirements: R2
}>
(parameter) policy: {
steps: NonEmptyReadonlyArray<{ readonly provide: Context.Context<Config["provides"]> | Layer.Layer<Config["provides"], Config["error"], Config["requirements"]>; readonly attempts?: number | undefined; readonly while?: ((input: Config["input"]) =>…;
captureRequirements: Effect.Effect<ExecutionPlan<{ provides: Config["provides"]; input: Config["input"]; error: Config["error"]; requirements: never }>, never, Config["requirements"]>;
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; <…;
}
policy: import ExecutionPlanExecutionPlan.type ExecutionPlan.ExecutionPlan = /*unresolved*/ anyExecutionPlan<{ provides: Providesprovides: function (type parameter) Provides in <Input, R2, Provides, PolicyE>(policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): <A, E extends Input, R>(self: Stream<A, E, R>) => Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Provides; input: Inputinput: function (type parameter) Input in <Input, R2, Provides, PolicyE>(policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): <A, E extends Input, R>(self: Stream<A, E, R>) => Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Input; error: PolicyEerror: function (type parameter) PolicyE in <Input, R2, Provides, PolicyE>(policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): <A, E extends Input, R>(self: Stream<A, E, R>) => Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
PolicyE; requirements: R2requirements: function (type parameter) R2 in <Input, R2, Provides, PolicyE>(policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): <A, E extends Input, R>(self: Stream<A, E, R>) => Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
R2 }>,
options: | {
readonly preventFallbackOnPartialStream?:
| boolean
| undefined
}
| undefined
options?: { readonly preventFallbackOnPartialStream?: boolean | undefinedpreventFallbackOnPartialStream?: boolean | undefined }
): <function (type parameter) A in <A, E extends Input, R>(self: Stream<A, E, R>): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>A, function (type parameter) E in <A, E extends Input, R>(self: Stream<A, E, R>): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>E extends function (type parameter) Input in <Input, R2, Provides, PolicyE>(policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): <A, E extends Input, R>(self: Stream<A, E, R>) => Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Input, function (type parameter) R in <A, E extends Input, R>(self: Stream<A, E, R>): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>R>(self: Stream<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<function (type parameter) A in <A, E extends Input, R>(self: Stream<A, E, R>): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>A, function (type parameter) E in <A, E extends Input, R>(self: Stream<A, E, R>): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>E, function (type parameter) R in <A, E extends Input, R>(self: Stream<A, E, R>): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>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 extends Input, R>(self: Stream<A, E, R>): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>A, function (type parameter) E in <A, E extends Input, R>(self: Stream<A, E, R>): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>E | function (type parameter) PolicyE in <Input, R2, Provides, PolicyE>(policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): <A, E extends Input, R>(self: Stream<A, E, R>) => Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
PolicyE, function (type parameter) R2 in <Input, R2, Provides, PolicyE>(policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): <A, E extends Input, R>(self: Stream<A, E, R>) => Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
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, E extends Input, R>(self: Stream<A, E, R>): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>R, function (type parameter) Provides in <Input, R2, Provides, PolicyE>(policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): <A, E extends Input, R>(self: Stream<A, E, R>) => Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Provides>>
<function (type parameter) A in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
A, function (type parameter) E in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
E extends function (type parameter) Input in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Input, function (type parameter) R in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
R, function (type parameter) R2 in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
R2, function (type parameter) Input in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Input, function (type parameter) Provides in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Provides, function (type parameter) PolicyE in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
PolicyE>(
self: Stream<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<function (type parameter) A in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
A, function (type parameter) E in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
E, function (type parameter) R in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
R>,
policy: ExecutionPlan.ExecutionPlan<{
provides: Provides
input: Input
error: PolicyE
requirements: R2
}>
(parameter) policy: {
steps: NonEmptyReadonlyArray<{ readonly provide: Context.Context<Config["provides"]> | Layer.Layer<Config["provides"], Config["error"], Config["requirements"]>; readonly attempts?: number | undefined; readonly while?: ((input: Config["input"]) =>…;
captureRequirements: Effect.Effect<ExecutionPlan<{ provides: Config["provides"]; input: Config["input"]; error: Config["error"]; requirements: never }>, never, Config["requirements"]>;
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; <…;
}
policy: import ExecutionPlanExecutionPlan.type ExecutionPlan.ExecutionPlan = /*unresolved*/ anyExecutionPlan<{ provides: Providesprovides: function (type parameter) Provides in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Provides; input: Inputinput: function (type parameter) Input in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Input; error: PolicyEerror: function (type parameter) PolicyE in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
PolicyE; requirements: R2requirements: function (type parameter) R2 in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
R2 }>,
options: | {
readonly preventFallbackOnPartialStream?:
| boolean
| undefined
}
| undefined
options?: { readonly preventFallbackOnPartialStream?: boolean | undefinedpreventFallbackOnPartialStream?: boolean | undefined }
): 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 extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
A, function (type parameter) E in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
E | function (type parameter) PolicyE in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
PolicyE, function (type parameter) R2 in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
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, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
R, function (type parameter) Provides in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Provides>>
} = import dualdual((args: anyargs) => const isStream: (
u: unknown
) => u is Stream<unknown, unknown, unknown>
Checks whether a value is a Stream.
Example (Checking whether a value is a Stream)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const stream = Stream.make(1, 2, 3)
const notStream = { data: [1, 2, 3] }
yield* Console.log(Stream.isStream(stream))
// true
yield* Console.log(Stream.isStream(notStream))
// false
})
Effect.runPromise(program)
isStream(args: anyargs[0]), <function (type parameter) A in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
A, function (type parameter) E in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
E extends function (type parameter) Input in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Input, function (type parameter) R in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
R, function (type parameter) R2 in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
R2, function (type parameter) Input in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Input, function (type parameter) Provides in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Provides, function (type parameter) PolicyE in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
PolicyE>(
self: Stream<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<function (type parameter) A in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
A, function (type parameter) E in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
E, function (type parameter) R in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
R>,
policy: ExecutionPlan.ExecutionPlan<{
provides: Provides
input: Input
error: PolicyE
requirements: R2
}>
(parameter) policy: {
steps: NonEmptyReadonlyArray<{ readonly provide: Context.Context<Config["provides"]> | Layer.Layer<Config["provides"], Config["error"], Config["requirements"]>; readonly attempts?: number | undefined; readonly while?: ((input: Config["input"]) =>…;
captureRequirements: Effect.Effect<ExecutionPlan<{ provides: Config["provides"]; input: Config["input"]; error: Config["error"]; requirements: never }>, never, Config["requirements"]>;
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; <…;
}
policy: import ExecutionPlanExecutionPlan.type ExecutionPlan.ExecutionPlan = /*unresolved*/ anyExecutionPlan<{
provides: Providesprovides: function (type parameter) Provides in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Provides
input: Inputinput: function (type parameter) Input in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Input
error: PolicyEerror: function (type parameter) PolicyE in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
PolicyE
requirements: R2requirements: function (type parameter) R2 in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
R2
}>,
options: | {
readonly preventFallbackOnPartialStream?:
| boolean
| undefined
}
| undefined
options?: {
readonly preventFallbackOnPartialStream?: boolean | undefinedpreventFallbackOnPartialStream?: boolean | undefined
}
): 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 extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
A, function (type parameter) E in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
E | function (type parameter) PolicyE in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
PolicyE, function (type parameter) R2 in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
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, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
R, function (type parameter) Provides in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Provides>> =>
const suspend: <A, E, R>(
stream: LazyArg<Stream<A, E, R>>
) => Stream<A, E, R>
Creates a lazily constructed stream.
Details
The stream factory is evaluated each time the stream is run.
Example (Creating a lazily constructed stream)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const values = yield* Stream.suspend(() => Stream.make(1, 2, 3)).pipe(Stream.runCollect)
yield* Console.log(values)
})
Effect.runPromise(program)
// Output: [ 1, 2, 3 ]
suspend(() => {
const const preventFallbackOnPartialStream: booleanpreventFallbackOnPartialStream = options: | {
readonly preventFallbackOnPartialStream?:
| boolean
| undefined
}
| undefined
options?.preventFallbackOnPartialStream?: boolean | undefinedpreventFallbackOnPartialStream ?? false
let let i: numberi = 0
let let meta: ExecutionPlan.Metadatalet meta: {
attempt: number;
stepIndex: number;
}
meta: import ExecutionPlanExecutionPlan.type ExecutionPlan.Metadata = /*unresolved*/ anyMetadata = {
attempt: numberattempt: 0,
stepIndex: numberstepIndex: 0
}
const const provideMeta: <A, E, R>(
self: Stream<A, E, R>
) => Stream<A, unknown, unknown>
provideMeta = const provideServiceEffect: {
<I, S, ES, RS>(
key: Context.Key<I, S>,
service: Effect.Effect<NoInfer<S>, ES, RS>
): <A, E, R>(
self: Stream<A, E, R>
) => Stream<A, E | ES, Exclude<R, I> | RS>
<A, E, R, I, S, ES, RS>(
self: Stream<A, E, R>,
key: Context.Key<I, S>,
service: Effect.Effect<NoInfer<S>, ES, RS>
): Stream<A, E | ES, Exclude<R, I> | RS>
}
provideServiceEffect(
import ExecutionPlanExecutionPlan.CurrentMetadata,
import EffectEffect.sync(() => {
let meta: ExecutionPlan.Metadatalet meta: {
attempt: number;
stepIndex: number;
}
meta = {
attempt: anyattempt: let meta: ExecutionPlan.Metadatalet meta: {
attempt: number;
stepIndex: number;
}
meta.attempt + 1,
stepIndex: numberstepIndex: let i: numberi
}
return let meta: ExecutionPlan.Metadatalet meta: {
attempt: number;
stepIndex: number;
}
meta
})
)
let let lastError: Option.Option<E | PolicyE>lastError = import OptionOption.none<function (type parameter) E in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
E | function (type parameter) PolicyE in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
PolicyE>()
const const loop: Stream<
A,
E | PolicyE,
R2 | Exclude<R, Provides>
>
const loop: {
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; <…;
}
loop: 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 extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
A,
function (type parameter) E in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
E | function (type parameter) PolicyE in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
PolicyE,
function (type parameter) R2 in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
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, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
R, function (type parameter) Provides in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Provides>
> = const suspend: <A, E, R>(
stream: LazyArg<Stream<A, E, R>>
) => Stream<A, E, R>
Creates a lazily constructed stream.
Details
The stream factory is evaluated each time the stream is run.
Example (Creating a lazily constructed stream)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const values = yield* Stream.suspend(() => Stream.make(1, 2, 3)).pipe(Stream.runCollect)
yield* Console.log(values)
})
Effect.runPromise(program)
// Output: [ 1, 2, 3 ]
suspend(() => {
const const step: anyconst step: {
provide: Context.Context<Config["provides"]> | Layer.Layer<Config["provides"], Config["error"], Config["requirements"]>;
attempts: number | undefined;
while: ((input: Config["input"]) => Effect.Effect<boolean, Config["error"], Config["requirements"]>) | undefined;
schedule: Schedule.Schedule<any, Config["input"], Config["requirements"]> | undefined;
}
step = policy: ExecutionPlan.ExecutionPlan<{
provides: Provides
input: Input
error: PolicyE
requirements: R2
}>
(parameter) policy: {
steps: NonEmptyReadonlyArray<{ readonly provide: Context.Context<Config["provides"]> | Layer.Layer<Config["provides"], Config["error"], Config["requirements"]>; readonly attempts?: number | undefined; readonly while?: ((input: Config["input"]) =>…;
captureRequirements: Effect.Effect<ExecutionPlan<{ provides: Config["provides"]; input: Config["input"]; error: Config["error"]; requirements: never }>, never, Config["requirements"]>;
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; <…;
}
policy.steps[let i: numberi]
if (!const step: anyconst step: {
provide: Context.Context<Config["provides"]> | Layer.Layer<Config["provides"], Config["error"], Config["requirements"]>;
attempts: number | undefined;
while: ((input: Config["input"]) => Effect.Effect<boolean, Config["error"], Config["requirements"]>) | undefined;
schedule: Schedule.Schedule<any, Config["input"], Config["requirements"]> | undefined;
}
step) {
return const fail: <E>(
error: E
) => Stream<never, E>
Terminates with the specified error.
Example (Failing a stream)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const stream = Stream.fail("Uh oh!")
const exit = yield* Effect.exit(Stream.runCollect(stream))
yield* Console.log(exit)
// Output: { _id: 'Exit', _tag: 'Failure', cause: { _id: 'Cause', _tag: 'Fail', failure: 'Uh oh!' } }
})
Effect.runPromise(program)
fail(import OptionOption.getOrThrow(let lastError: Option.Option<E | PolicyE>lastError))
}
let let nextStream: Stream<
A,
E | PolicyE,
R2 | Exclude<R, Provides>
>
let nextStream: {
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; <…;
}
nextStream: 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 extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
A, function (type parameter) E in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
E | function (type parameter) PolicyE in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
PolicyE, function (type parameter) R2 in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
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, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
R, function (type parameter) Provides in <A, E extends Input, R, R2, Input, Provides, PolicyE>(self: Stream<A, E, R>, policy: ExecutionPlan.ExecutionPlan<{
provides: Provides;
input: Input;
error: PolicyE;
requirements: R2;
}>, options?: {
readonly preventFallbackOnPartialStream?: boolean | undefined;
}): Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>
Provides>> = const provideMeta: <A, E, Exclude<R, unknown>>(self: Stream<A, E, Exclude<R, unknown>>) => Stream<A, unknown, unknown>provideMeta(const provide: {
<AL, EL = never, RL = never>(
layer:
| Layer.Layer<AL, EL, RL>
| Context.Context<AL>,
options?:
| { readonly local?: boolean | undefined }
| undefined
): <A, E, R>(
self: Stream<A, E, R>
) => Stream<A, E | EL, Exclude<R, AL> | RL>
<A, E, R, AL, EL = never, RL = never>(
self: Stream<A, E, R>,
layer:
| Layer.Layer<AL, EL, RL>
| Context.Context<AL>,
options?:
| { readonly local?: boolean | undefined }
| undefined
): Stream<A, E | EL, Exclude<R, AL> | RL>
}
provide(self: Stream<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 step: anyconst step: {
provide: Context.Context<Config["provides"]> | Layer.Layer<Config["provides"], Config["error"], Config["requirements"]>;
attempts: number | undefined;
while: ((input: Config["input"]) => Effect.Effect<boolean, Config["error"], Config["requirements"]>) | undefined;
schedule: Schedule.Schedule<any, Config["input"], Config["requirements"]> | undefined;
}
step.provide))
let let receivedElements: booleanreceivedElements = false
if (import OptionOption.isSome(let lastError: Option.Option<E | PolicyE>lastError)) {
const const error: anyerror = let lastError: Option.Some<E | PolicyE>let lastError: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
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;
}
lastError.value
let let attempted: booleanattempted = false
const const wrapped: Stream<
A,
E | PolicyE,
R2 | Exclude<R, Provides>
>
const wrapped: {
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; <…;
}
wrapped = let nextStream: Stream<
A,
E | PolicyE,
R2 | Exclude<R, Provides>
>
let nextStream: {
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; <…;
}
nextStream
// ensure the schedule is applied at least once
let nextStream: Stream<
A,
E | PolicyE,
R2 | Exclude<R, Provides>
>
let nextStream: {
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; <…;
}
nextStream = const suspend: <A, E, R>(
stream: LazyArg<Stream<A, E, R>>
) => Stream<A, E, R>
Creates a lazily constructed stream.
Details
The stream factory is evaluated each time the stream is run.
Example (Creating a lazily constructed stream)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const values = yield* Stream.suspend(() => Stream.make(1, 2, 3)).pipe(Stream.runCollect)
yield* Console.log(values)
})
Effect.runPromise(program)
// Output: [ 1, 2, 3 ]
suspend(() => {
if (let attempted: booleanattempted) return const wrapped: Stream<
A,
E | PolicyE,
R2 | Exclude<R, Provides>
>
const wrapped: {
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; <…;
}
wrapped
let attempted: booleanattempted = true
return const fail: <E>(
error: E
) => Stream<never, E>
Terminates with the specified error.
Example (Failing a stream)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const stream = Stream.fail("Uh oh!")
const exit = yield* Effect.exit(Stream.runCollect(stream))
yield* Console.log(exit)
// Output: { _id: 'Exit', _tag: 'Failure', cause: { _id: 'Cause', _tag: 'Fail', failure: 'Uh oh!' } }
})
Effect.runPromise(program)
fail(const error: anyerror)
})
let nextStream: Stream<
A,
E | PolicyE,
R2 | Exclude<R, Provides>
>
let nextStream: {
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; <…;
}
nextStream = const retry: {
<E, X, E2, R2>(
policy:
| Schedule.Schedule<X, NoInfer<E>, E2, R2>
| ((
$: <SO, SE, SR>(
_: Schedule.Schedule<
SO,
NoInfer<E>,
SE,
SR
>
) => Schedule.Schedule<SO, E, SE, SR>
) => Schedule.Schedule<
X,
NoInfer<E>,
E2,
R2
>)
): <A, R>(
self: Stream<A, E, R>
) => Stream<A, E | E2, R2 | R>
<A, E, R, X, E2, R2>(
self: Stream<A, E, R>,
policy:
| Schedule.Schedule<X, NoInfer<E>, E2, R2>
| ((
$: <SO, SE, SR>(
_: Schedule.Schedule<
SO,
NoInfer<E>,
SE,
SR
>
) => Schedule.Schedule<SO, E, SE, SR>
) => Schedule.Schedule<
X,
NoInfer<E>,
E2,
R2
>)
): Stream<A, E | E2, R2 | R>
}
retry(let nextStream: Stream<
A,
E | PolicyE,
R2 | Exclude<R, Provides>
>
let nextStream: {
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; <…;
}
nextStream, import internalExecutionPlaninternalExecutionPlan.const scheduleFromStep: <
Provides,
In,
PlanE,
PlanR
>(
step: Api.ExecutionPlan<{
provides: Provides
input: In
error: PlanE
requirements: PlanR
}>["steps"][number],
first: boolean
) =>
| Schedule.Schedule<any, In, any, any>
| undefined
scheduleFromStep(const step: anyconst step: {
provide: Context.Context<Config["provides"]> | Layer.Layer<Config["provides"], Config["error"], Config["requirements"]>;
attempts: number | undefined;
while: ((input: Config["input"]) => Effect.Effect<boolean, Config["error"], Config["requirements"]>) | undefined;
schedule: Schedule.Schedule<any, Config["input"], Config["requirements"]> | undefined;
}
step, false) as any)
} else {
const const schedule: anyschedule = import internalExecutionPlaninternalExecutionPlan.const scheduleFromStep: <
Provides,
In,
PlanE,
PlanR
>(
step: Api.ExecutionPlan<{
provides: Provides
input: In
error: PlanE
requirements: PlanR
}>["steps"][number],
first: boolean
) =>
| Schedule.Schedule<any, In, any, any>
| undefined
scheduleFromStep(const step: anyconst step: {
provide: Context.Context<Config["provides"]> | Layer.Layer<Config["provides"], Config["error"], Config["requirements"]>;
attempts: number | undefined;
while: ((input: Config["input"]) => Effect.Effect<boolean, Config["error"], Config["requirements"]>) | undefined;
schedule: Schedule.Schedule<any, Config["input"], Config["requirements"]> | undefined;
}
step, true)
let nextStream: Stream<
A,
E | PolicyE,
R2 | Exclude<R, Provides>
>
let nextStream: {
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; <…;
}
nextStream = const schedule: anyschedule ? const retry: {
<E, X, E2, R2>(
policy:
| Schedule.Schedule<X, NoInfer<E>, E2, R2>
| ((
$: <SO, SE, SR>(
_: Schedule.Schedule<
SO,
NoInfer<E>,
SE,
SR
>
) => Schedule.Schedule<SO, E, SE, SR>
) => Schedule.Schedule<
X,
NoInfer<E>,
E2,
R2
>)
): <A, R>(
self: Stream<A, E, R>
) => Stream<A, E | E2, R2 | R>
<A, E, R, X, E2, R2>(
self: Stream<A, E, R>,
policy:
| Schedule.Schedule<X, NoInfer<E>, E2, R2>
| ((
$: <SO, SE, SR>(
_: Schedule.Schedule<
SO,
NoInfer<E>,
SE,
SR
>
) => Schedule.Schedule<SO, E, SE, SR>
) => Schedule.Schedule<
X,
NoInfer<E>,
E2,
R2
>)
): Stream<A, E | E2, R2 | R>
}
retry(let nextStream: Stream<
A,
E | PolicyE,
R2 | Exclude<R, Provides>
>
let nextStream: {
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; <…;
}
nextStream, const schedule: Schedule.Schedule<
any,
Input,
any,
any
>
const schedule: {
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; <…;
}
schedule as any) : let nextStream: Stream<
A,
E | PolicyE,
R2 | Exclude<R, Provides>
>
let nextStream: {
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; <…;
}
nextStream
}
return const catch_: {
<E, A2, E2, R2>(
f: (error: E) => Stream<A2, E2, R2>
): <A, R>(
self: Stream<A, E, R>
) => Stream<A | A2, E2, R2 | R>
<A, E, R, A2, E2, R2>(
self: Stream<A, E, R>,
f: (error: E) => Stream<A2, E2, R2>
): Stream<A | A2, E2, R | R2>
}
catch_(
const preventFallbackOnPartialStream: booleanpreventFallbackOnPartialStream ?
const onFirst: {
<A, X, EX, RX>(
onFirst: (
element: NoInfer<A>
) => Effect.Effect<X, EX, RX>
): <E, R>(
self: Stream<A, E, R>
) => Stream<A, E | EX, R | RX>
<A, E, R, X, EX, RX>(
self: Stream<A, E, R>,
onFirst: (
element: NoInfer<A>
) => Effect.Effect<X, EX, RX>
): Stream<A, E | EX, R | RX>
}
onFirst(let nextStream: Stream<
A,
E | PolicyE,
R2 | Exclude<R, Provides>
>
let nextStream: {
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; <…;
}
nextStream, (_: NoInfer<A>_) => {
let receivedElements: booleanreceivedElements = true
return import EffectEffect.void
}) :
let nextStream: Stream<
A,
E | PolicyE,
R2 | Exclude<R, Provides>
>
let nextStream: {
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; <…;
}
nextStream,
(error: E | PolicyEerror) => {
let i: numberi++
if (const preventFallbackOnPartialStream: booleanpreventFallbackOnPartialStream && let receivedElements: booleanreceivedElements) {
return const fail: <E>(
error: E
) => Stream<never, E>
Terminates with the specified error.
Example (Failing a stream)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const stream = Stream.fail("Uh oh!")
const exit = yield* Effect.exit(Stream.runCollect(stream))
yield* Console.log(exit)
// Output: { _id: 'Exit', _tag: 'Failure', cause: { _id: 'Cause', _tag: 'Fail', failure: 'Uh oh!' } }
})
Effect.runPromise(program)
fail(error: E | PolicyEerror)
}
let lastError: Option.Option<E | PolicyE>lastError = import OptionOption.some(error: E | PolicyEerror)
return const loop: Stream<
A,
E | PolicyE,
R2 | Exclude<R, Provides>
>
const loop: {
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; <…;
}
loop
}
)
})
return const loop: Stream<
A,
E | PolicyE,
R2 | Exclude<R, Provides>
>
const loop: {
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; <…;
}
loop
}))