<B, E2, R2>(options: {
readonly duration: Duration.Input
readonly orElse: () => Stream<B, E2, R2>
}): <A, E, R>(self: Stream<A, E, R>) => Stream<A | B, E | E2, R | R2>
<A, E, R, B, E2, R2>(
self: Stream<A, E, R>,
options: {
readonly duration: Duration.Input
readonly orElse: () => Stream<B, E2, R2>
}
): Stream<A | B, E | E2, R | R2>Switches to a fallback stream if this stream does not emit a value within the specified duration.
When to use
Use when a stream should continue with another stream if an upstream pull waits longer than the allowed duration.
Details
The timeout is checked for each pull. A zero duration uses orElse
immediately, while an infinite duration leaves the original stream
unchanged.
Gotchas
The fallback stream is not timed after the switch.
export const const timeoutOrElse: {
<B, E2, R2>(options: {
readonly duration: Duration.Input
readonly orElse: () => Stream<B, E2, R2>
}): <A, E, R>(
self: Stream<A, E, R>
) => Stream<A | B, E | E2, R | R2>
<A, E, R, B, E2, R2>(
self: Stream<A, E, R>,
options: {
readonly duration: Duration.Input
readonly orElse: () => Stream<B, E2, R2>
}
): Stream<A | B, E | E2, R | R2>
}
Switches to a fallback stream if this stream does not emit a value within
the specified duration.
When to use
Use when a stream should continue with another stream if an upstream pull
waits longer than the allowed duration.
Details
The timeout is checked for each pull. A zero duration uses orElse
immediately, while an infinite duration leaves the original stream
unchanged.
Gotchas
The fallback stream is not timed after the switch.
timeoutOrElse: {
<function (type parameter) B in <B, E2, R2>(options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): <A, E, R>(self: Stream<A, E, R>) => Stream<A | B, E | E2, R | R2>
B, function (type parameter) E2 in <B, E2, R2>(options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): <A, E, R>(self: Stream<A, E, R>) => Stream<A | B, E | E2, R | R2>
E2, function (type parameter) R2 in <B, E2, R2>(options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): <A, E, R>(self: Stream<A, E, R>) => Stream<A | B, E | E2, R | R2>
R2>(options: {
readonly duration: Duration.Input
readonly orElse: () => Stream<B, E2, R2>
}
options: {
readonly duration: Duration.Inputduration: import DurationDuration.type Duration.Input = /*unresolved*/ anyInput
readonly orElse: () => Stream<B, E2, R2>orElse: () => 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) B in <B, E2, R2>(options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): <A, E, R>(self: Stream<A, E, R>) => Stream<A | B, E | E2, R | R2>
B, function (type parameter) E2 in <B, E2, R2>(options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): <A, E, R>(self: Stream<A, E, R>) => Stream<A | B, E | E2, R | R2>
E2, function (type parameter) R2 in <B, E2, R2>(options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): <A, E, R>(self: Stream<A, E, R>) => Stream<A | B, E | E2, R | R2>
R2>
}): <function (type parameter) A in <A, E, R>(self: Stream<A, E, R>): Stream<A | B, E | E2, R | R2>A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>): Stream<A | B, E | E2, R | R2>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>): Stream<A | B, E | E2, R | R2>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, R>(self: Stream<A, E, R>): Stream<A | B, E | E2, R | R2>A, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>): Stream<A | B, E | E2, R | R2>E, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>): Stream<A | B, E | E2, R | R2>R>) => interface Stream<out A, out E = never, out R = never>A Stream<A, E, R> describes a program that can emit many A values, fail
with E, and require R.
Details
Streams are pull-based with backpressure and emit chunks to amortize effect
evaluation. They support monadic composition and error handling similar to
Effect, adapted for multiple values.
Example (Creating and consuming streams)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.make(1, 2, 3).pipe(
Stream.map((n) => n * 2),
Stream.runForEach((n) => Console.log(n))
)
})
Effect.runPromise(program)
// Output:
// 2
// 4
// 6
Stream<function (type parameter) A in <A, E, R>(self: Stream<A, E, R>): Stream<A | B, E | E2, R | R2>A | function (type parameter) B in <B, E2, R2>(options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): <A, E, R>(self: Stream<A, E, R>) => Stream<A | B, E | E2, R | R2>
B, function (type parameter) E in <A, E, R>(self: Stream<A, E, R>): Stream<A | B, E | E2, R | R2>E | function (type parameter) E2 in <B, E2, R2>(options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): <A, E, R>(self: Stream<A, E, R>) => Stream<A | B, E | E2, R | R2>
E2, function (type parameter) R in <A, E, R>(self: Stream<A, E, R>): Stream<A | B, E | E2, R | R2>R | function (type parameter) R2 in <B, E2, R2>(options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): <A, E, R>(self: Stream<A, E, R>) => Stream<A | B, E | E2, R | R2>
R2>
<function (type parameter) A in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
A, function (type parameter) E in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
E, function (type parameter) R in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
R, function (type parameter) B in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
B, function (type parameter) E2 in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
E2, function (type parameter) R2 in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
R2>(
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, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
A, function (type parameter) E in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
E, function (type parameter) R in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
R>,
options: {
readonly duration: Duration.Input
readonly orElse: () => Stream<B, E2, R2>
}
options: {
readonly duration: Duration.Inputduration: import DurationDuration.type Duration.Input = /*unresolved*/ anyInput
readonly orElse: () => Stream<B, E2, R2>orElse: () => 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) B in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
B, function (type parameter) E2 in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
E2, function (type parameter) R2 in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
R2>
}
): interface Stream<out A, out E = never, out R = never>A Stream<A, E, R> describes a program that can emit many A values, fail
with E, and require R.
Details
Streams are pull-based with backpressure and emit chunks to amortize effect
evaluation. They support monadic composition and error handling similar to
Effect, adapted for multiple values.
Example (Creating and consuming streams)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.make(1, 2, 3).pipe(
Stream.map((n) => n * 2),
Stream.runForEach((n) => Console.log(n))
)
})
Effect.runPromise(program)
// Output:
// 2
// 4
// 6
Stream<function (type parameter) A in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
A | function (type parameter) B in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
B, function (type parameter) E in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
E | function (type parameter) E2 in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
E2, function (type parameter) R in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
R | function (type parameter) R2 in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
R2>
} = import dualdual(
2,
<function (type parameter) A in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
A, function (type parameter) E in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
E, function (type parameter) R in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
R, function (type parameter) B in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
B, function (type parameter) E2 in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
E2, function (type parameter) R2 in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
R2>(
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, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
A, function (type parameter) E in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
E, function (type parameter) R in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
R>,
options: {
readonly duration: Duration.Input
readonly orElse: () => Stream<B, E2, R2>
}
options: {
readonly duration: Duration.Inputduration: import DurationDuration.type Duration.Input = /*unresolved*/ anyInput
readonly orElse: () => Stream<B, E2, R2>orElse: () => 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) B in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
B, function (type parameter) E2 in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
E2, function (type parameter) R2 in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
R2>
}
): interface Stream<out A, out E = never, out R = never>A Stream<A, E, R> describes a program that can emit many A values, fail
with E, and require R.
Details
Streams are pull-based with backpressure and emit chunks to amortize effect
evaluation. They support monadic composition and error handling similar to
Effect, adapted for multiple values.
Example (Creating and consuming streams)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.make(1, 2, 3).pipe(
Stream.map((n) => n * 2),
Stream.runForEach((n) => Console.log(n))
)
})
Effect.runPromise(program)
// Output:
// 2
// 4
// 6
Stream<function (type parameter) A in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
A | function (type parameter) B in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
B, function (type parameter) E in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
E | function (type parameter) E2 in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
E2, function (type parameter) R in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
R | function (type parameter) R2 in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
R2> => {
const const duration: Duration.Durationconst duration: {
value: DurationValue;
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;
}
duration = import DurationDuration.fromInputUnsafe(options: {
readonly duration: Duration.Input
readonly orElse: () => Stream<B, E2, R2>
}
options.duration: Duration.Inputduration)
if (!import DurationDuration.isFinite(const duration: Duration.Durationconst duration: {
value: DurationValue;
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;
}
duration)) return 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
if (import DurationDuration.isZero(const duration: Duration.Durationconst duration: {
value: DurationValue;
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;
}
duration)) return 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(options: {
readonly duration: Duration.Input
readonly orElse: () => Stream<B, E2, R2>
}
options.orElse: () => Stream<B, E2, R2>orElse)
const const timeoutSymbol: unique symboltimeoutSymbol = var Symbol: SymbolConstructor
;(description?: string | number) => symbol
Returns a new unique Symbol value.
Symbol()
return const catchCause: {
<E, A2, E2, R2>(
f: (
cause: Cause.Cause<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: (
cause: Cause.Cause<E>
) => Stream<A2, E2, R2>
): Stream<A | A2, E2, R | R2>
}
catchCause(
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 parent: Fiber.Fiber<any, any>const parent: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | 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; <…;
}
parent = import FiberFiber.getCurrent()!
const const clock: Clockconst clock: {
currentTimeMillisUnsafe: () => number;
currentTimeMillis: Effect<number>;
currentTimeNanosUnsafe: () => bigint;
currentTimeNanos: Effect<bigint>;
sleep: (duration: Duration.Duration) => Effect<void>;
}
clock = const parent: Fiber.Fiber<any, any>const parent: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | 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; <…;
}
parent.getRef(import ClockClock)
const const durationMs: anydurationMs = import DurationDuration.toMillis(const duration: Duration.Durationconst duration: {
value: DurationValue;
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;
}
duration)
let let deadline: number | undefineddeadline: number | undefined = var undefinedundefined
const const latch: Latch.Latchconst latch: {
open: Effect.Effect<boolean>;
openUnsafe: (this: Latch) => boolean;
release: Effect.Effect<boolean>;
await: Effect.Effect<void>;
close: Effect.Effect<boolean>;
closeUnsafe: (this: Latch) => boolean;
whenOpen: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
isOpen: (this: Latch) => boolean;
}
latch = import LatchLatch.makeUnsafe(false)
return const merge: {
<A2, E2, R2>(
that: Stream<A2, E2, R2>,
options?:
| {
readonly haltStrategy?:
| HaltStrategy
| undefined
}
| undefined
): <A, E, R>(
self: Stream<A, E, R>
) => Stream<A | A2, E | E2, R | R2>
<A, E, R, A2, E2, R2>(
self: Stream<A, E, R>,
that: Stream<A2, E2, R2>,
options?:
| {
readonly haltStrategy?:
| HaltStrategy
| undefined
}
| undefined
): Stream<A | A2, E | E2, R | R2>
}
merge(
const transformPull: <
A,
E,
R,
B,
E2,
R2,
EX,
RX
>(
self: Stream<A, E, R>,
f: (
pull: Pull.Pull<
Arr.NonEmptyReadonlyArray<A>,
E,
void
>,
scope: Scope.Scope
) => Effect.Effect<
Pull.Pull<
Arr.NonEmptyReadonlyArray<B>,
E2,
void,
R2
>,
EX,
RX
>
) => Stream<
B,
EX | Pull.ExcludeDone<E2>,
R | R2 | RX
>
Derives a stream by transforming its pull effect.
Example (Transforming a pull effect)
import { Console, Effect, Stream } from "effect"
const stream = Stream.make(1, 2, 3)
const transformed = Stream.transformPull(stream, (pull) => Effect.succeed(pull))
const program = Effect.gen(function*() {
const values = yield* Stream.runCollect(transformed)
yield* Console.log(values)
})
Effect.runPromise(program)
// Output: [ 1, 2, 3 ]
transformPull(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, (pull: Pull.Pull<
readonly [A, ...A[]],
E,
void,
never
>
(parameter) pull: {
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;
}
pull, _scope: Scope.Scope(parameter) _scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
_scope) =>
import EffectEffect.suspend(() => {
let deadline: number | undefineddeadline = const clock: Clockconst clock: {
currentTimeMillisUnsafe: () => number;
currentTimeMillis: Effect<number>;
currentTimeNanosUnsafe: () => bigint;
currentTimeNanos: Effect<bigint>;
sleep: (duration: Duration.Duration) => Effect<void>;
}
clock.currentTimeMillisUnsafe() + const durationMs: anydurationMs
const latch: Latch.Latchconst latch: {
open: Effect.Effect<boolean>;
openUnsafe: (this: Latch) => boolean;
release: Effect.Effect<boolean>;
await: Effect.Effect<void>;
close: Effect.Effect<boolean>;
closeUnsafe: (this: Latch) => boolean;
whenOpen: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
isOpen: (this: Latch) => boolean;
}
latch.openUnsafe()
return pull: Pull.Pull<
readonly [A, ...A[]],
E,
void,
never
>
(parameter) pull: {
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;
}
pull
}).pipe(
import EffectEffect.map((arr: any(parameter) arr: {
0: A;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<A>>): Array<A>; (...items: Array<A | ConcatArray<A>>): Array<A> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<A>;
indexOf: (searchElement: A, fromIndex?: number) => number;
lastIndexOf: (searchElement: A, fromIndex?: number) => number;
every: { (predicate: (value: A, index: number, array: ReadonlyArray<A>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: A, index: number, array: ReadonlyArray<A>) => void, thisArg?: any) => void;
map: (callbackfn: (value: A, index: number, array: ReadonlyArray<A>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: A, index: number, array: ReadonlyArray<A>) => value is S, thisArg?: any): Array<S>; (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any): Array<A> };
reduce: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A, initialValue: A): A; (callbac…;
reduceRight: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A, initialValue: A): A; (callbac…;
find: { (predicate: (value: A, index: number, obj: ReadonlyArray<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, obj: ReadonlyArray<A>) => unknown, thisArg?: any): A | undefined };
findIndex: (predicate: (value: A, index: number, obj: ReadonlyArray<A>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, A]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<A>;
includes: (searchElement: A, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: A, index: number, array: Array<A>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => A | undefined;
findLast: { (predicate: (value: A, index: number, array: ReadonlyArray<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any): A | undefined };
findLastIndex: (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any) => number;
toReversed: () => Array<A>;
toSorted: (compareFn?: ((a: A, b: A) => number) | undefined) => Array<A>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<A>): Array<A>; (start: number, deleteCount?: number): Array<A> };
with: (index: number, value: A) => Array<A>;
}
arr) => {
const latch: Latch.Latchconst latch: {
open: Effect.Effect<boolean>;
openUnsafe: (this: Latch) => boolean;
release: Effect.Effect<boolean>;
await: Effect.Effect<void>;
close: Effect.Effect<boolean>;
closeUnsafe: (this: Latch) => boolean;
whenOpen: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
isOpen: (this: Latch) => boolean;
}
latch.closeUnsafe()
let deadline: number | undefineddeadline = var undefinedundefined
return arr: any(parameter) arr: {
0: A;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<A>>): Array<A>; (...items: Array<A | ConcatArray<A>>): Array<A> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<A>;
indexOf: (searchElement: A, fromIndex?: number) => number;
lastIndexOf: (searchElement: A, fromIndex?: number) => number;
every: { (predicate: (value: A, index: number, array: ReadonlyArray<A>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: A, index: number, array: ReadonlyArray<A>) => void, thisArg?: any) => void;
map: (callbackfn: (value: A, index: number, array: ReadonlyArray<A>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: A, index: number, array: ReadonlyArray<A>) => value is S, thisArg?: any): Array<S>; (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any): Array<A> };
reduce: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A, initialValue: A): A; (callbac…;
reduceRight: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A, initialValue: A): A; (callbac…;
find: { (predicate: (value: A, index: number, obj: ReadonlyArray<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, obj: ReadonlyArray<A>) => unknown, thisArg?: any): A | undefined };
findIndex: (predicate: (value: A, index: number, obj: ReadonlyArray<A>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, A]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<A>;
includes: (searchElement: A, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: A, index: number, array: Array<A>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => A | undefined;
findLast: { (predicate: (value: A, index: number, array: ReadonlyArray<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any): A | undefined };
findLastIndex: (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any) => number;
toReversed: () => Array<A>;
toSorted: (compareFn?: ((a: A, b: A) => number) | undefined) => Array<A>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<A>): Array<A>; (start: number, deleteCount?: number): Array<A> };
with: (index: number, value: A) => Array<A>;
}
arr
}),
import EffectEffect.succeed
)),
const fromEffectDrain: <A, E, R>(
effect: Effect.Effect<A, E, R>
) => Stream<never, E, R>
Creates a stream that runs the effect and emits no elements.
Example (Draining an effect into a stream)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.fromEffectDrain(Console.log("Draining side effect")).pipe(
Stream.runDrain
)
})
Effect.runPromise(program)
// Output: Draining side effect
fromEffectDrain(import EffectEffect.gen(function*() {
while (true) {
yield* const latch: Latch.Latchconst latch: {
open: Effect.Effect<boolean>;
openUnsafe: (this: Latch) => boolean;
release: Effect.Effect<boolean>;
await: Effect.Effect<void>;
close: Effect.Effect<boolean>;
closeUnsafe: (this: Latch) => boolean;
whenOpen: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
isOpen: (this: Latch) => boolean;
}
latch.await
if (let deadline: number | undefineddeadline === var undefinedundefined) continue
yield* import EffectEffect.sleep(let deadline: numberdeadline - const clock: Clockconst clock: {
currentTimeMillisUnsafe: () => number;
currentTimeMillis: Effect<number>;
currentTimeNanosUnsafe: () => bigint;
currentTimeNanos: Effect<bigint>;
sleep: (duration: Duration.Duration) => Effect<void>;
}
clock.currentTimeMillisUnsafe())
if (let deadline: numberdeadline === var undefinedundefined) continue
const const remaining: numberremaining = let deadline: numberdeadline - const clock: Clockconst clock: {
currentTimeMillisUnsafe: () => number;
currentTimeMillis: Effect<number>;
currentTimeNanosUnsafe: () => bigint;
currentTimeNanos: Effect<bigint>;
sleep: (duration: Duration.Duration) => Effect<void>;
}
clock.currentTimeMillisUnsafe()
if (const remaining: numberremaining > 0) continue
return yield* import EffectEffect.die(const timeoutSymbol: unique symboltimeoutSymbol)
}
})),
{ haltStrategy?: anyhaltStrategy: "left" }
)
}),
(cause: Cause.Cause<Exclude<E, Cause.Done<any>>>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
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;
}
cause): 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) B in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
B, function (type parameter) E in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
E | function (type parameter) E2 in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
E2, function (type parameter) R2 in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
R2> => {
const const isTimeout: anyisTimeout = cause: Cause.Cause<Exclude<E, Cause.Done<any>>>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
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;
}
cause.reasons.find((r: Cause.Reason<
Exclude<E, Cause.Done<any>>
>
r) => r: Cause.Reason<
Exclude<E, Cause.Done<any>>
>
r._tag === "Die" && r: Cause.Die(parameter) r: {
defect: unknown;
_tag: Tag;
annotations: ReadonlyMap<string, unknown>;
annotate: (annotations: Context.Context<never> | ReadonlyMap<string, unknown>, options?: { readonly overwrite?: boolean | undefined }) => Cause.Die;
toString: () => string;
toJSON: () => unknown;
}
r.defect === const timeoutSymbol: unique symboltimeoutSymbol)
if (const isTimeout: anyisTimeout) return options: {
readonly duration: Duration.Input
readonly orElse: () => Stream<B, E2, R2>
}
options.orElse: () => Stream<B, E2, R2>orElse()
return const failCause: <E>(
cause: Cause.Cause<E>
) => Stream<never, E>
Creates a stream that fails with the specified Cause.
Example (Failing with a cause)
import { Cause, Console, Effect, Stream } from "effect"
const stream = Stream.failCause(Cause.fail("Database connection failed")).pipe(
Stream.catchCause(() => Stream.succeed("recovered"))
)
const program = Effect.gen(function*() {
const values = yield* Stream.runCollect(stream)
yield* Console.log(values)
// Output: [ "recovered" ]
})
Effect.runPromise(program)
failCause(cause: Cause.Cause<Exclude<E, Cause.Done<any>>>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
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;
}
cause as import CauseCause.type Cause.Cause = /*unresolved*/ anyCause<function (type parameter) E in <A, E, R, B, E2, R2>(self: Stream<A, E, R>, options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream<B, E2, R2>;
}): Stream<A | B, E | E2, R | R2>
E>)
}
)
}
)