<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.interface ExecutionPlan<Config extends { provides: any; input: any; error: any; requirements: any; }>A ExecutionPlan can be used with Effect.withExecutionPlan or Stream.withExecutionPlan, allowing you to provide different resources for each step of execution until the effect succeeds or the plan is exhausted.
Example (Defining fallback execution steps)
import { Effect, ExecutionPlan, Schedule } from "effect"
import type { Layer } from "effect"
import type { LanguageModel } from "effect/unstable/ai"
declare const layerBad: Layer.Layer<LanguageModel.LanguageModel>
declare const layerGood: Layer.Layer<LanguageModel.LanguageModel>
const ThePlan = ExecutionPlan.make(
{
// First try with the bad layer 2 times with a 3 second delay between attempts
provide: layerBad,
attempts: 2,
schedule: Schedule.spaced(3000)
},
// Then try with the bad layer 3 times with a 1 second delay between attempts
{
provide: layerBad,
attempts: 3,
schedule: Schedule.spaced(1000)
},
// Finally try with the good layer.
//
// If `attempts` is omitted, the plan will only attempt once, unless a schedule is provided.
{
provide: layerGood
}
)
declare const effect: Effect.Effect<
void,
never,
LanguageModel.LanguageModel
>
const withPlan: Effect.Effect<void> = Effect.withExecutionPlan(effect, ThePlan)
ExecutionPlan<{ 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.interface ExecutionPlan<Config extends { provides: any; input: any; error: any; requirements: any; }>A ExecutionPlan can be used with Effect.withExecutionPlan or Stream.withExecutionPlan, allowing you to provide different resources for each step of execution until the effect succeeds or the plan is exhausted.
Example (Defining fallback execution steps)
import { Effect, ExecutionPlan, Schedule } from "effect"
import type { Layer } from "effect"
import type { LanguageModel } from "effect/unstable/ai"
declare const layerBad: Layer.Layer<LanguageModel.LanguageModel>
declare const layerGood: Layer.Layer<LanguageModel.LanguageModel>
const ThePlan = ExecutionPlan.make(
{
// First try with the bad layer 2 times with a 3 second delay between attempts
provide: layerBad,
attempts: 2,
schedule: Schedule.spaced(3000)
},
// Then try with the bad layer 3 times with a 1 second delay between attempts
{
provide: layerBad,
attempts: 3,
schedule: Schedule.spaced(1000)
},
// Finally try with the good layer.
//
// If `attempts` is omitted, the plan will only attempt once, unless a schedule is provided.
{
provide: layerGood
}
)
declare const effect: Effect.Effect<
void,
never,
LanguageModel.LanguageModel
>
const withPlan: Effect.Effect<void> = Effect.withExecutionPlan(effect, ThePlan)
ExecutionPlan<{ 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>>
} = dual<(...args: Array<any>) => any, <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>>>(isDataFirst: (args: IArguments) => boolean, body: <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>>): ((...args: Array<any>) => any) & (<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>>) (+1 overload)
Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual((args: IArgumentsargs) => 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: IArgumentsargs[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.interface ExecutionPlan<Config extends { provides: any; input: any; error: any; requirements: any; }>A ExecutionPlan can be used with Effect.withExecutionPlan or Stream.withExecutionPlan, allowing you to provide different resources for each step of execution until the effect succeeds or the plan is exhausted.
Example (Defining fallback execution steps)
import { Effect, ExecutionPlan, Schedule } from "effect"
import type { Layer } from "effect"
import type { LanguageModel } from "effect/unstable/ai"
declare const layerBad: Layer.Layer<LanguageModel.LanguageModel>
declare const layerGood: Layer.Layer<LanguageModel.LanguageModel>
const ThePlan = ExecutionPlan.make(
{
// First try with the bad layer 2 times with a 3 second delay between attempts
provide: layerBad,
attempts: 2,
schedule: Schedule.spaced(3000)
},
// Then try with the bad layer 3 times with a 1 second delay between attempts
{
provide: layerBad,
attempts: 3,
schedule: Schedule.spaced(1000)
},
// Finally try with the good layer.
//
// If `attempts` is omitted, the plan will only attempt once, unless a schedule is provided.
{
provide: layerGood
}
)
declare const effect: Effect.Effect<
void,
never,
LanguageModel.LanguageModel
>
const withPlan: Effect.Effect<void> = Effect.withExecutionPlan(effect, ThePlan)
ExecutionPlan<{
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.Metadata = {
Metadata.attempt: numberattempt: 0,
Metadata.stepIndex: numberstepIndex: 0
}
const const provideMeta: <A, E, R>(
self: Stream<A, E, R>
) => Stream<A, E, Exclude<R, never>>
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.const CurrentMetadata: Context.Reference<ExecutionPlan.Metadata>const CurrentMetadata: {
key: string;
Service: {
attempt: number;
stepIndex: number;
};
defaultValue: () => Shape;
of: (this: void, self: ExecutionPlan.Metadata) => ExecutionPlan.Metadata;
context: (self: ExecutionPlan.Metadata) => Context.Context<never>;
use: (f: (service: ExecutionPlan.Metadata) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
useSync: (f: (service: ExecutionPlan.Metadata) => A) => Effect.Effect<A, never, never>;
Identifier: Identifier;
stack: string | undefined;
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;
}
Context reference containing metadata for the currently running
execution-plan attempt.
When to use
Use to read the active plan step and attempt while code is running under an
execution plan.
CurrentMetadata,
import EffectEffect.const sync: <A>(
thunk: LazyArg<A>
) => Effect<A>
Creates an Effect that represents a synchronous side-effectful computation.
When to use
Use when you need to wrap a synchronous side-effectful operation that is not
expected to throw.
Details
The provided function is evaluated lazily when the effect runs.
Gotchas
The function must not throw. If it throws, the thrown value is treated as a
defect, not as a typed failure. Use try when throwing is expected.
Example (Capturing synchronous logging in an Effect)
import { Effect } from "effect"
const log = (message: string) =>
Effect.sync(() => {
console.log(message) // side effect
})
// ┌─── Effect<void, never, never>
// ▼
const program = log("Hello, World!")
sync(() => {
let meta: ExecutionPlan.Metadatalet meta: {
attempt: number;
stepIndex: number;
}
meta = {
Metadata.attempt: numberattempt: let meta: ExecutionPlan.Metadatalet meta: {
attempt: number;
stepIndex: number;
}
meta.Metadata.attempt: numberattempt + 1,
Metadata.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.const none: <A = never>() => Option<A>Creates an Option representing the absence of a value.
When to use
Use to represent a missing or uninitialized value, such as returning "no
result" from a function.
Details
- Returns
Option<never>, which is a subtype of Option<A> for any A
- Always returns the same singleton instance
Example (Creating an empty Option)
import { Option } from "effect"
// ┌─── Option<never>
// ▼
const noValue = Option.none()
console.log(noValue)
// Output: { _id: 'Option', _tag: 'None' }
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: {
readonly provide:
| Context.Context<Provides>
| Layer.Layer<Provides, PolicyE, R2>
readonly attempts?: number | undefined
readonly while?:
| ((
input: Input
) => Effect.Effect<boolean, PolicyE, R2>)
| undefined
readonly schedule?:
| Schedule.Schedule<any, Input, R2, never>
| 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.ExecutionPlan<{ provides: Provides; input: Input; error: PolicyE; requirements: R2; }>.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"]) => Effect.Effect<boolean, Config["error"], Config["requirements"]>) | undefined; readonly schedule?: Schedule.Schedule<any, Config["input"], Config["requirements"]> | undefined }>(property) ExecutionPlan<{ provides: Provides; input: Input; error: PolicyE; requirements: R2; }>.steps: {
0: { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined; readonly schedule?: Schedule.…;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<{ readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined…;
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<{ readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | …;
indexOf: (searchElement: { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined; readonly sche…;
lastIndexOf: (searchElement: { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined; readonly sche…;
every: { (predicate: (value: { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined; readonl…;
some: (predicate: (value: { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined; readonly …;
forEach: (callbackfn: (value: { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined; readonly…;
map: (callbackfn: (value: { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined; readonly…;
filter: { (predicate: (value: { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined; readonl…;
reduce: { (callbackfn: (previousValue: { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined…;
reduceRight: { (callbackfn: (previousValue: { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined…;
find: { (predicate: (value: { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined; readonl…;
findIndex: (predicate: (value: { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined; readonly …;
entries: () => ArrayIterator<[number, { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined; …;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<{ readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined; readonly …;
includes: (searchElement: { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined; readonly sche…;
flatMap: (callback: (this: This, value: { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined…;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined; readonly s…;
findLast: { (predicate: (value: { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined; readonl…;
findLastIndex: (predicate: (value: { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined; readonly …;
toReversed: () => Array<{ readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined; readonly schedule…;
toSorted: (compareFn?: ((a: { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined; readonly sc…;
toSpliced: { (start: number, deleteCount: number, ...items: Array<{ readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, P…;
with: (index: number, value: { readonly provide: Context.Context<Provides> | Layer.Layer<Provides, PolicyE, R2>; readonly attempts?: number | undefined; readonly while?: ((input: Input) => Effect.Effect<boolean, PolicyE, R2>) | undefined; readon…;
}
steps[let i: numberi]
if (!const step: {
readonly provide:
| Context.Context<Provides>
| Layer.Layer<Provides, PolicyE, R2>
readonly attempts?: number | undefined
readonly while?:
| ((
input: Input
) => Effect.Effect<boolean, PolicyE, R2>)
| undefined
readonly schedule?:
| Schedule.Schedule<any, Input, R2, never>
| 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.const getOrThrow: <A>(
self: Option<A>
) => A
Extracts the value from a Some, or throws a default Error for None.
When to use
Use when you need quick fail-fast unwrapping of an Option and a generic
error is acceptable.
Details
Some → returns the inner value
None → throws new Error("getOrThrow called on a None")
Example (Throwing a default error)
import { Option } from "effect"
console.log(Option.getOrThrow(Option.some(1)))
// Output: 1
Option.getOrThrow(Option.none())
// throws Error: getOrThrow called on a None
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 | PolicyE, R2 | Exclude<R, Provides>>(self: Stream<A, E | PolicyE, R2 | Exclude<R, Provides>>) => Stream<A, E | PolicyE, Exclude<R2, never> | Exclude<Exclude<R, Provides>, never>>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: {
readonly provide:
| Context.Context<Provides>
| Layer.Layer<Provides, PolicyE, R2>
readonly attempts?: number | undefined
readonly while?:
| ((
input: Input
) => Effect.Effect<boolean, PolicyE, R2>)
| undefined
readonly schedule?:
| Schedule.Schedule<any, Input, R2, never>
| undefined
}
step.provide: | Context.Context<Config["provides"]>
| Layer.Layer<
Config["provides"],
Config["error"],
Config["requirements"]
>
provide))
let let receivedElements: booleanreceivedElements = false
if (import OptionOption.const isSome: <A>(
self: Option<A>
) => self is Some<A>
Checks whether an Option contains a value (Some).
When to use
Use when you need to branch on a present Option before accessing .value.
Details
- Acts as a type guard, narrowing to
Some<A>
Example (Checking for Some)
import { Option } from "effect"
console.log(Option.isSome(Option.some(1)))
// Output: true
console.log(Option.isSome(Option.none()))
// Output: false
isSome(let lastError: Option.Option<E | PolicyE>lastError)) {
const const error: E | PolicyEerror = 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.Some<E | PolicyE>.value: E | PolicyEvalue
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: E | PolicyEerror)
})
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: {
readonly provide:
| Context.Context<Provides>
| Layer.Layer<Provides, PolicyE, R2>
readonly attempts?: number | undefined
readonly while?:
| ((
input: Input
) => Effect.Effect<boolean, PolicyE, R2>)
| undefined
readonly schedule?:
| Schedule.Schedule<any, Input, R2, never>
| undefined
}
step, false) as any)
} else {
const const schedule:
| Schedule.Schedule<any, Input, any, any>
| undefined
schedule = 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: {
readonly provide:
| Context.Context<Provides>
| Layer.Layer<Provides, PolicyE, R2>
readonly attempts?: number | undefined
readonly while?:
| ((
input: Input
) => Effect.Effect<boolean, PolicyE, R2>)
| undefined
readonly schedule?:
| Schedule.Schedule<any, Input, R2, never>
| 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:
| Schedule.Schedule<any, Input, any, any>
| undefined
schedule ? 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.const void: Effect.Effect<void, never, never>(alias) const void: {
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;
}
Returns an effect that succeeds with void.
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.const some: <A>(value: A) => Option<A>Wraps the given value into an Option to represent its presence.
When to use
Use to wrap a known present value as Option
- Returning a successful result from a partial function
Details
- Always returns
Some<A>
- Does not filter
null or undefined; use
fromNullishOr
for that
Example (Wrapping a value)
import { Option } from "effect"
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
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
}))