diff --git "a/.opencode/node_modules/effect/dist/Stream.d.ts" "b/.opencode/node_modules/effect/dist/Stream.d.ts"
--- "a/.opencode/node_modules/effect/dist/Stream.d.ts"
+++ "b/.opencode/node_modules/effect/dist/Stream.d.ts"
@@ -1,4 +1,13 @@
/**
+ * Describes effectful sources that emit values over time.
+ *
+ * A `Stream` can emit many `A` values, fail with `E`, and require
+ * services `R` while it is being consumed. Streams are useful for data that is
+ * pulled in steps, such as values from collections, queues, pubsubs, schedules,
+ * callbacks, async iterables, or platform streams. The APIs here cover the full
+ * stream lifecycle: create a stream, transform or combine it, control buffering
+ * and timing, handle failures, and finally consume it.
+ *
* @since 2.0.0
*/
import * as Arr from "./Array.ts";
@@ -17,7 +26,7 @@ import type { Severity } from "./LogLevel.ts";
import * as Option from "./Option.ts";
import type { Pipeable } from "./Pipeable.ts";
import type { Predicate, Refinement } from "./Predicate.ts";
-import type * as PubSub from "./PubSub.ts";
+import * as PubSub from "./PubSub.ts";
import * as Pull from "./Pull.ts";
import * as Queue from "./Queue.ts";
import * as Result from "./Result.ts";
@@ -26,27 +35,42 @@ import * as Scope from "./Scope.ts";
import * as Sink from "./Sink.ts";
import type * as Take from "./Take.ts";
import type { ParentSpan, SpanOptions } from "./Tracer.ts";
-import type { Covariant, ExcludeReason, ExcludeTag, ExtractReason, ExtractTag, NarrowReason, NoInfer, OmitReason, ReasonTags, Tags, unassigned } from "./Types.ts";
+import type { Covariant, ExcludeReason, ExcludeTag, ExtractReason, ExtractTag, NarrowReason, NoInfer, OmitReason, ReasonTags, Tags, TupleOf, unassigned } from "./Types.ts";
import type * as Unify from "./Unify.ts";
/**
+ * String literal type used as the unique brand for `Stream` values.
+ *
+ * @category type IDs
* @since 4.0.0
- * @category Type Identifiers
*/
export type TypeId = "~effect/Stream";
/**
+ * Runtime identifier stored on `Stream` values and used by `isStream` to
+ * recognize them.
+ *
+ * **Details**
+ *
+ * This marker is part of the runtime representation of `Stream` values. Prefer
+ * `isStream` when narrowing unknown values.
+ *
+ * @see {@link isStream} for the public guard that checks this identifier
+ *
+ * @category type IDs
* @since 4.0.0
- * @category Type Identifiers
*/
export declare const TypeId: TypeId;
/**
* A `Stream` 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
+ * **Example** (Creating and consuming streams)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -64,8 +88,8 @@ export declare const TypeId: TypeId;
* // 6
* ```
*
+ * @category models
* @since 2.0.0
- * @category Models
*/
export interface Stream extends Variance, Pipeable {
readonly channel: Channel.Channel, E, void, unknown, unknown, unknown, R>;
@@ -76,20 +100,8 @@ export interface Stream extends Variance
- * declare const effect: Effect.Effect
- *
- * // The unification system handles mixed operations
- * const combined = Effect.zip(stream.pipe(Stream.runCollect), effect)
- * ```
- *
+ * @category models
* @since 2.0.0
- * @category Models
*/
export interface StreamUnify
+ * type NumberStream = HKT.Kind
* // Equivalent to: Stream
* ```
*
- * @category Type Lambdas
+ * @category type lambdas
* @since 2.0.0
*/
export interface StreamTypeLambda extends TypeLambda {
readonly type: Stream;
}
/**
- * Variance markers for Stream type parameters.
+ * Type-level variance marker for `Stream`.
*
+ * **Details**
+ *
+ * The emitted value `A`, error `E`, and service requirement `R` type
+ * parameters are covariant.
+ *
+ * @category models
* @since 2.0.0
- * @category Models
*/
export interface Variance {
readonly [TypeId]: VarianceStruct;
}
/**
- * Structural encoding of Stream type parameter variance.
+ * Structural encoding used by `Variance` to record each `Stream` type
+ * parameter's variance.
*
- * @since 2.0.0
- * @category Models
+ * **Details**
+ *
+ * `_A`, `_E`, and `_R` are covariant markers.
+ *
+ * @category models
+ * @since 3.4.0
*/
export interface VarianceStruct {
readonly _A: Covariant;
@@ -156,7 +169,8 @@ export interface VarianceStruct {
/**
* Extract the success type from a Stream type.
*
- * @example
+ * **Example** (Extracting the success type from a Stream type)
+ *
* ```ts
* import type { Stream } from "effect"
*
@@ -165,14 +179,15 @@ export interface VarianceStruct {
* // SuccessType is number
* ```
*
+ * @category utility types
* @since 3.4.0
- * @category Type-Level
*/
export type Success> = [T] extends [Stream] ? _A : never;
/**
* Extract the error type from a Stream type.
*
- * @example
+ * **Example** (Extracting the error type from a Stream type)
+ *
* ```ts
* import type { Stream } from "effect"
*
@@ -181,18 +196,15 @@ export type Success> = [T] extends [Stream> = [T] extends [Stream] ? _E : never;
/**
* Extract the services type from a Stream type.
*
- * **Previously Known As:**
+ * **Example** (Extracting the services type from a Stream type)
*
- * This type alias was named `Context` in Effect 3.x.
- *
- * @example
* ```ts
* import type { Stream } from "effect"
*
@@ -204,14 +216,15 @@ export type Error> = [T] extends [Stream> = [T] extends [Stream] ? _R : never;
/**
* Checks whether a value is a Stream.
*
- * @example
+ * **Example** (Checking whether a value is a Stream)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -228,14 +241,15 @@ export type Services> = [T] extends [Stream u is Stream;
/**
* The default chunk size used by Stream constructors and combinators.
*
- * @example
+ * **Example** (Reading the default chunk size)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -247,27 +261,22 @@ export declare const isStream: (u: unknown) => u is Stream, E, R>(channel: Channel.Channel) => Stream ? A : never, E, R>;
/**
- * Either emits the success value of this effect or terminates the stream
- * with the failure value of this effect.
+ * Creates a stream from an effect.
+ *
+ * **Example** (Creating a stream from an effect)
*
- * @example
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -303,16 +312,17 @@ export declare const fromChannel: , E
* // Output: [ 42 ]
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const fromEffect: (effect: Effect.Effect) => Stream;
/**
* Accesses a service from the context and emits it as a single element.
*
- * @example
+ * **Example** (Accessing a service as a stream)
+ *
* ```ts
- * import { Effect, Context, Stream } from "effect"
+ * import { Context, Effect, Stream } from "effect"
*
* class Greeter extends Context.Service string
@@ -335,17 +345,23 @@ export declare const fromEffect: (effect: Effect.Effect) => St
* // Output: [ "Hello, World!" ]
* ```
*
+ * @category context
* @since 4.0.0
- * @category Context
*/
export declare const service: (service: Context.Key) => Stream;
/**
* Optionally accesses a service from the context and emits the result as a
* single element.
*
- * @example
+ * **When to use**
+ *
+ * Use when you need a stream that emits an optional service from the context
+ * without requiring that service to be present.
+ *
+ * **Example** (Accessing an optional service as a stream)
+ *
* ```ts
- * import { Effect, Option, Context, Stream } from "effect"
+ * import { Context, Effect, Option, Stream } from "effect"
*
* class Greeter extends Context.Service string
@@ -373,14 +389,15 @@ export declare const service: (service: Context.Key) => Stream(service: Context.Key) => Stream>;
/**
* Creates a stream that runs the effect and emits no elements.
*
- * @example
+ * **Example** (Draining an effect into a stream)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -394,20 +411,15 @@ export declare const serviceOption: (service: Context.Key) => Stream
* // Output: Draining side effect
* ```
*
+ * @category constructors
* @since 4.0.0
- * @category Constructors
*/
export declare const fromEffectDrain: (effect: Effect.Effect) => Stream;
/**
* Creates a stream from an effect producing a value of type `A` which repeats forever.
*
- * **Previously Known As**
- *
- * This API replaces the following from Effect 3.x:
+ * **Example** (Repeating an effect forever)
*
- * - `Stream.repeatEffect`
- *
- * @example
* ```ts
* import { Console, Effect, Random, Stream } from "effect"
*
@@ -423,21 +435,16 @@ export declare const fromEffectDrain: (effect: Effect.Effect)
* // Output: [ 3891571149, 4239494205, 2352981603, 2339111046, 1488052210 ]
* ```
*
+ * @category constructors
* @since 4.0.0
- * @category Constructors
*/
export declare const fromEffectRepeat: (effect: Effect.Effect) => Stream, R>;
/**
* Creates a stream from an effect producing a value of type `A`, which is
* repeated using the specified schedule.
*
- * **Previously Known As**
- *
- * This API replaces the following from Effect 3.x:
+ * **Example** (Repeating an effect with a schedule)
*
- * - `Stream.repeatEffectWithSchedule`
- *
- * @example
* ```ts
* import { Console, Effect, Schedule, Stream } from "effect"
*
@@ -454,14 +461,16 @@ export declare const fromEffectRepeat: (effect: Effect.Effect)
* // Output: [ "ping", "ping", "ping" ]
* ```
*
- * @since 2.0.0
- * @category Constructors
+ * @category constructors
+ * @since 4.0.0
*/
export declare const fromEffectSchedule: (effect: Effect.Effect, schedule: Schedule.Schedule) => Stream;
/**
- * Creates a stream that emits void values spaced by the specified duration.
+ * Creates a stream that emits `void` immediately once, then emits another
+ * `void` after each specified interval.
+ *
+ * **Example** (Emitting ticks on an interval)
*
- * @example
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -477,17 +486,20 @@ export declare const fromEffectSchedule: (effe
* // Output: [ undefined, undefined, undefined ]
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const tick: (interval: Duration.Input) => Stream;
/**
* Creates a stream from a pull effect, such as one produced by `Stream.toPull`.
*
+ * **Details**
+ *
* A pull effect yields chunks on demand and completes when the upstream stream ends.
* See `Stream.toPull` for a matching producer.
*
- * @example
+ * **Example** (Creating a stream from a pull effect)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -505,14 +517,15 @@ export declare const tick: (interval: Duration.Input) => Stream;
* // Output: [1, 2, 3]
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const fromPull: (pull: Effect.Effect, E, void, R>, EX, RX>) => Stream | EX, R | RX>;
/**
- * Derive a stream by transforming its pull effect.
+ * Derives a stream by transforming its pull effect.
+ *
+ * **Example** (Transforming a pull effect)
*
- * @example
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -529,17 +542,20 @@ export declare const fromPull: (pull: Effect.Effect(self: Stream, f: (pull: Pull.Pull, E, void>, scope: Scope.Scope) => Effect.Effect, E2, void, R2>, EX, RX>) => Stream, R | R2 | RX>;
/**
* Transforms a stream by effectfully transforming its pull effect.
*
+ * **Details**
+ *
* A forked scope is also provided to the transformation function, which is
* closed once the resulting stream has finished processing.
*
- * @example
+ * **Example** (Transforming a stream by effectfully transforming its pull effect)
+ *
* ```ts
* import { Console, Effect, Scope, Stream } from "effect"
*
@@ -564,14 +580,15 @@ export declare const transformPull: (self: Stream(self: Stream, f: (pull: Pull.Pull, E, void, R>, scope: Scope.Scope, forkedScope: Scope.Scope) => Effect.Effect, E2, void, R2>, EX, RX>) => Stream, R | R2 | RX>;
/**
* Creates a channel from a stream.
*
- * @example
+ * **Example** (Converting a stream to a channel)
+ *
* ```ts
* import { Channel, Console, Effect, Stream } from "effect"
*
@@ -586,30 +603,24 @@ export declare const transformPullBracket: (self: St
* // Output: [ 1, 2, 3 ]
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const toChannel: (stream: Stream) => Channel.Channel, E, void, unknown, unknown, unknown, R>;
/**
* Creates a stream from a callback that can emit values into a queue.
*
- * You can use the `Queue` with the apis from the `Queue` module to emit
- * values to the stream or to signal the stream ending.
+ * **When to use**
+ *
+ * Use when you need callback-based code to emit stream values by offering to a
+ * `Queue`, or signal stream completion through the `Queue` module APIs.
*
* By default it uses an "unbounded" buffer size.
* You can customize the buffer size and strategy by passing an object as the
* second argument with the `bufferSize` and `strategy` fields.
*
- * **Previously Known As**
- *
- * This API replaces the following from Effect 3.x:
+ * **Example** (Creating a stream from a callback that can emit values into a queue)
*
- * - `Stream.async`
- * - `Stream.asyncEffect`
- * - `Stream.asyncPush`
- * - `Stream.asyncScoped`
- *
- * @example
* ```ts
* import { Console, Effect, Queue, Stream } from "effect"
*
@@ -633,8 +644,8 @@ export declare const toChannel: (stream: Stream) => Channel.Ch
* Effect.runPromise(program)
* ```
*
- * @since 2.0.0
- * @category Constructors
+ * @category constructors
+ * @since 4.0.0
*/
export declare const callback: (f: (queue: Queue.Queue) => Effect.Effect, options?: {
readonly bufferSize?: number | undefined;
@@ -643,7 +654,8 @@ export declare const callback: (f: (queue: Queue.Queue<
/**
* Creates an empty stream.
*
- * @example
+ * **Example** (Creating an empty stream)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -656,14 +668,15 @@ export declare const callback: (f: (queue: Queue.Queue<
* // []
* ```
*
- * @since 4.0.0
- * @category Constructors
+ * @category constructors
+ * @since 2.0.0
*/
export declare const empty: Stream;
/**
* Creates a single-valued pure stream.
*
- * @example
+ * **Example** (Creating a single-valued pure stream)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -676,14 +689,15 @@ export declare const empty: Stream;
* // [ 3 ]
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const succeed: (value: A) => Stream;
/**
* Creates a stream from a sequence of values.
*
- * @example
+ * **Example** (Creating a stream from a sequence of values)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -697,16 +711,19 @@ export declare const succeed: (value: A) => Stream;
* Effect.runPromise(program)
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const make: >(...values: As) => Stream;
/**
* Creates a stream that synchronously evaluates a function and emits the result as a single value.
*
+ * **Details**
+ *
* The function is evaluated each time the stream is run.
*
- * @example
+ * **Example** (Evaluating a value synchronously)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -719,16 +736,19 @@ export declare const make: >(...values: As)
* // Output: [ 3 ]
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const sync: (evaluate: LazyArg) => Stream;
/**
* Creates a lazily constructed stream.
*
+ * **Details**
+ *
* The stream factory is evaluated each time the stream is run.
*
- * @example
+ * **Example** (Creating a lazily constructed stream)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -741,14 +761,15 @@ export declare const sync: (evaluate: LazyArg) => Stream;
* // Output: [ 1, 2, 3 ]
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const suspend: (stream: LazyArg>) => Stream;
/**
* Terminates with the specified error.
*
- * @example
+ * **Example** (Failing a stream)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -762,14 +783,15 @@ export declare const suspend: (stream: LazyArg>) => Str
* Effect.runPromise(program)
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const fail: (error: E) => Stream;
/**
* Terminates with the specified lazily evaluated error.
*
- * @example
+ * **Example** (Failing a stream lazily)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -785,14 +807,15 @@ export declare const fail: (error: E) => Stream;
* // { _id: 'Exit', _tag: 'Failure', cause: { _id: 'Cause', _tag: 'Fail', failure: 'Uh oh!' } }
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const failSync: (evaluate: LazyArg) => Stream;
/**
* Creates a stream that fails with the specified `Cause`.
*
- * @example
+ * **Example** (Failing with a cause)
+ *
* ```ts
* import { Cause, Console, Effect, Stream } from "effect"
*
@@ -809,14 +832,15 @@ export declare const failSync: (evaluate: LazyArg) => Stream;
* Effect.runPromise(program)
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const failCause: (cause: Cause.Cause) => Stream;
/**
* The stream that dies with the specified defect.
*
- * @example
+ * **Example** (Dying with a defect)
+ *
* ```ts
* import { Cause, Console, Effect, Exit, Stream } from "effect"
*
@@ -840,14 +864,15 @@ export declare const failCause: (cause: Cause.Cause) => Stream;
* // Output: Exit.Failure(Error: Boom)
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const die: (defect: unknown) => Stream;
/**
* The stream that always fails with the specified lazily evaluated `Cause`.
*
- * @example
+ * **Example** (Failing with a lazy cause)
+ *
* ```ts
* import { Cause, Console, Effect, Stream } from "effect"
*
@@ -865,16 +890,19 @@ export declare const die: (defect: unknown) => Stream;
* // { _id: 'Exit', _tag: 'Failure', cause: { _id: 'Cause', _tag: 'Fail', failure: 'Connection timeout after retries' } }
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const failCauseSync: (evaluate: LazyArg>) => Stream;
/**
* Creates a stream that consumes values from an iterator.
*
+ * **Details**
+ *
* The `maxChunkSize` parameter controls how many values are pulled per chunk.
*
- * @example
+ * **Example** (Consuming values from an iterator)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -895,18 +923,19 @@ export declare const failCauseSync: (evaluate: LazyArg>) => St
* // Output: [ 1, 2, 3 ]
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const fromIteratorSucceed: (iterator: IterableIterator, maxChunkSize?: number) => Stream;
/**
* Creates a new `Stream` from an iterable collection of values.
*
- * **Options**
+ * **Details**
*
* - `chunkSize`: Maximum number of values emitted per chunk.
*
- * @example
+ * **Example** (Creating a stream from an iterable)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -922,8 +951,8 @@ export declare const fromIteratorSucceed: (iterator: IterableIterator, max
* // Output: [ 1, 2, 3 ]
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const fromIterable: (iterable: Iterable, options?: {
readonly chunkSize?: number | undefined;
@@ -931,9 +960,15 @@ export declare const fromIterable: (iterable: Iterable, options?: {
/**
* Creates a stream from an effect producing an iterable of values.
*
- * @example
+ * **When to use**
+ *
+ * Use when the iterable must be acquired from an Effect before the stream emits,
+ * and acquisition services or failures should be part of the stream.
+ *
+ * **Example** (Creating a stream from an iterable effect)
+ *
* ```ts
- * import { Console, Effect, Context, Stream } from "effect"
+ * import { Console, Context, Effect, Stream } from "effect"
*
* class UserRepo extends Context.Service>
@@ -959,20 +994,15 @@ export declare const fromIterable: (iterable: Iterable, options?: {
* // Output: [ "user1", "user2" ]
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const fromIterableEffect: (iterable: Effect.Effect, E, R>) => Stream;
/**
* Creates a stream by repeatedly running an effect that yields an iterable of values.
*
- * **Previously Known As**
- *
- * This API replaces the following from Effect 3.x:
+ * **Example** (Repeating an iterable effect)
*
- * - `Stream.repeatEffectChunk`
- *
- * @example
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -988,20 +1018,15 @@ export declare const fromIterableEffect: (iterable: Effect.Effect(iterable: Effect.Effect, E, R>) => Stream, R>;
/**
* Creates a stream from an array of values.
*
- * **Previously Known As**
- *
- * This API replaces the following from Effect 3.x:
+ * **Example** (Creating a stream from an array of values)
*
- * - `Stream.fromChunk`
- *
- * @example
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -1015,14 +1040,20 @@ export declare const fromIterableEffectRepeat: (iterable: Effect.Effect
* // Output: [ 1, 2, 3 ]
* ```
*
+ * @category constructors
* @since 4.0.0
- * @category Constructors
*/
export declare const fromArray: (array: ReadonlyArray) => Stream;
/**
* Creates a stream from an effect that produces an array of values.
*
- * @example
+ * **When to use**
+ *
+ * Use when the array must be acquired from an Effect before the stream emits,
+ * and acquisition services or failures should be part of the stream.
+ *
+ * **Example** (Creating a stream from an effect that produces an array of values)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -1036,20 +1067,15 @@ export declare const fromArray: (array: ReadonlyArray) => Stream;
* // Output: [ "Ada", "Grace" ]
* ```
*
+ * @category constructors
* @since 4.0.0
- * @category Constructors
*/
export declare const fromArrayEffect: (effect: Effect.Effect, E, R>) => Stream, R>;
/**
* Creates a stream from an arbitrary number of arrays.
*
- * **Previously Known As**
+ * **Example** (Creating a stream from an arbitrary number of arrays)
*
- * This API replaces the following from Effect 3.x:
- *
- * - `Stream.fromChunks`
- *
- * @example
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -1063,19 +1089,20 @@ export declare const fromArrayEffect: (effect: Effect.Effect>>(...arrays: Arr) => Stream;
/**
- * Creates a stream from a queue of values.
+ * Creates a stream that pulls values from a `Queue.Dequeue`.
*
- * **Options**
+ * **Details**
*
- * - `maxChunkSize`: The maximum number of queued elements to put in one chunk in the stream
- * - `shutdown`: If `true`, the queue will be shutdown after the stream is evaluated (defaults to `false`)
+ * The stream emits non-empty batches of queued values and ends when the queue
+ * fails with `Cause.Done`; other queue failures are propagated.
+ *
+ * **Example** (Creating a stream from a queue of values)
*
- * @example
* ```ts
* import { Console, Effect, Queue, Stream } from "effect"
*
@@ -1095,14 +1122,15 @@ export declare const fromArrays: >>
* // Output: [ 1, 2, 3 ]
* ```
*
- * @since 4.0.0
- * @category Constructors
+ * @category constructors
+ * @since 2.0.0
*/
export declare const fromQueue: (queue: Queue.Dequeue) => Stream>;
/**
* Creates a stream from a subscription to a `PubSub`.
*
- * @example
+ * **Example** (Creating a stream from a subscription to a PubSub)
+ *
* ```ts
* import { Console, Effect, Fiber, PubSub, Stream } from "effect"
*
@@ -1127,16 +1155,19 @@ export declare const fromQueue: (queue: Queue.Dequeue) => Stream(pubsub: PubSub.PubSub) => Stream;
/**
* Creates a stream from a PubSub of `Take` values.
*
+ * **Details**
+ *
* `Take` values include end and failure signals.
*
- * @example
+ * **Example** (Creating a stream from PubSub takes)
+ *
* ```ts
* import { Console, Effect, Exit, PubSub, Stream, Take } from "effect"
*
@@ -1157,16 +1188,21 @@ export declare const fromPubSub: (pubsub: PubSub.PubSub) => Stream;
* // Output: [ 1, 2 ]
* ```
*
+ * @category constructors
* @since 4.0.0
- * @category Constructors
*/
export declare const fromPubSubTake: (pubsub: PubSub.PubSub>) => Stream;
/**
- * Creates a stream from a `ReadableStream`.
+ * Creates a stream from a lazily supplied Web `ReadableStream`.
*
- * See https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream.
+ * **Details**
+ *
+ * The stream reads from a `ReadableStreamDefaultReader`, maps read failures
+ * with `onError`, and closes the reader when the stream finalizes. By default
+ * the reader is canceled; set `releaseLockOnEnd` to release the lock instead.
+ *
+ * **Example** (Creating a stream from a ReadableStream)
*
- * @example
* ```ts
* import { Console, Data, Effect, Stream } from "effect"
*
@@ -1194,8 +1230,8 @@ export declare const fromPubSubTake: (pubsub: PubSub.PubSub(options: {
readonly evaluate: LazyArg>;
@@ -1205,9 +1241,10 @@ export declare const fromReadableStream: (options: {
/**
* Creates a stream from an AsyncIterable.
*
- * @example
+ * **Example** (Creating a stream from an AsyncIterable)
+ *
* ```ts
- * import { Console, Data, Effect, Stream } from "effect"
+ * import { Data, Effect, Stream } from "effect"
*
* class StreamError extends Data.TaggedError("StreamError")<{ readonly cause: unknown }> {}
*
@@ -1217,25 +1254,25 @@ export declare const fromReadableStream: (options: {
* yield 3
* })()
*
- * const program = Effect.gen(function*() {
+ * Effect.runPromise(Effect.gen(function*() {
* const stream = Stream.fromAsyncIterable(iterable, (cause) => new StreamError({ cause }))
* const values = yield* Stream.runCollect(stream)
- * yield* Console.log(values)
- * })
+ * yield* Effect.sync(() => console.log(values))
+ * }))
*
- * Effect.runPromise(program)
- * // Output: [ 1, 2, 3 ]
+ * // [ 1, 2, 3 ]
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const fromAsyncIterable: (iterable: AsyncIterable, onError: (error: unknown) => E) => Stream;
/**
* Creates a stream that emits each output of a schedule that does not require input,
* for as long as the schedule continues.
*
- * @example
+ * **Example** (Creating a stream from a schedule)
+ *
* ```ts
* import { Console, Effect, Schedule, Stream } from "effect"
*
@@ -1252,17 +1289,21 @@ export declare const fromAsyncIterable: (iterable: AsyncIterable, onErr
* // Output: [ 0, 1, 2 ]
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const fromSchedule: (schedule: Schedule.Schedule) => Stream;
/**
* Creates a stream from a PubSub subscription.
*
- * Use `PubSub.subscribe` to create the subscription and `Stream.take` or
- * cancellation to control how many values are consumed.
+ * **When to use**
+ *
+ * Use when you already have a `PubSub.Subscription` and want to expose its
+ * messages as a `Stream`, with `Stream.take` or cancellation controlling how
+ * many values are consumed.
+ *
+ * **Example** (Creating a stream from a PubSub subscription)
*
- * @example
* ```ts
* import { Console, Effect, PubSub, Stream } from "effect"
*
@@ -1282,15 +1323,15 @@ export declare const fromSchedule: (schedule: Schedule.Schedule(pubsub: PubSub.Subscription) => Stream;
/**
* Interface representing an event listener target.
*
+ * @category models
* @since 3.4.0
- * @category Models
*/
export interface EventListener {
addEventListener(event: string, f: (event: A) => void, options?: {
@@ -1306,26 +1347,35 @@ export interface EventListener {
/**
* Creates a stream from an event listener.
*
- * @example
+ * **Example** (Creating a stream from an event listener)
+ *
* ```ts
- * import { Console, Effect, Stream } from "effect"
+ * import { Effect, Stream } from "effect"
*
- * declare const target: Stream.EventListener
+ * class NumberTarget implements Stream.EventListener {
+ * addEventListener(event: string, f: (event: number) => void) {
+ * if (event === "data") {
+ * f(1)
+ * f(2)
+ * f(3)
+ * }
+ * }
+ * removeEventListener(_event: string, _f: (event: number) => void) {}
+ * }
*
- * const program = Effect.gen(function*() {
- * const stream = Stream.fromEventListener(target, "data").pipe(
+ * Effect.runPromise(Effect.gen(function*() {
+ * const stream = Stream.fromEventListener(new NumberTarget(), "data").pipe(
* Stream.take(3)
* )
* const values = yield* Stream.runCollect(stream)
- * yield* Console.log(values)
- * })
+ * yield* Effect.sync(() => console.log(values))
+ * }))
*
- * Effect.runPromise(program)
- * // Output: [ 1, 2, 3 ]
+ * // [ 1, 2, 3 ]
* ```
*
+ * @category constructors
* @since 3.1.0
- * @category Constructors
*/
export declare const fromEventListener: (target: EventListener, type: string, options?: boolean | {
readonly capture?: boolean;
@@ -1334,9 +1384,16 @@ export declare const fromEventListener: (target: EventListener,
readonly bufferSize?: number | undefined;
} | undefined) => Stream;
/**
- * Creates a stream by peeling off successive layers of a state value.
+ * Creates a stream by repeatedly applying an effectful step function to a
+ * state.
+ *
+ * **Details**
+ *
+ * Each `readonly [value, nextState]` result emits `value` and continues with
+ * `nextState`; returning `undefined` ends the stream.
+ *
+ * **Example** (Unfolding stream state)
*
- * @example
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -1350,19 +1407,27 @@ export declare const fromEventListener: (target: EventListener,
* // Output: [ 1, 2, 3, 4, 5 ]
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const unfold: (s: S, f: (s: S) => Effect.Effect) => Stream;
/**
- * Like `Stream.unfold`, but allows the emission of values to end one step further
- * than the unfolding of the state. This is useful for embedding paginated APIs,
- * hence the name.
+ * Creates a stream by repeatedly evaluating an effectful page function.
+ *
+ * **When to use**
+ *
+ * Use to consume paginated APIs where each step returns a batch of values
+ * together with an optional next state.
+ *
+ * **Details**
+ *
+ * This is similar to {@link unfold}, but each step can emit zero or more values
+ * and independently decide whether another state should be requested.
+ *
+ * **Example** (Paginating stream state)
*
- * @example
* ```ts
- * import { Console, Effect, Stream } from "effect"
- * import * as Option from "effect/Option"
+ * import { Console, Effect, Option, Stream } from "effect"
*
* const stream = Stream.paginate(0, (n: number) =>
* Effect.succeed(
@@ -1376,14 +1441,15 @@ export declare const unfold: (s: S, f: (s: S) => Effect.Effect(s: S, f: (s: S) => Effect.Effect, Option.Option], E, R>) => Stream;
/**
* Creates an infinite stream by repeatedly applying a function to a seed value.
*
- * @example
+ * **Example** (Iterating from a seed value)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -1398,17 +1464,20 @@ export declare const paginate: (s: S, f: (s: S) => E
* // Output: [ 1, 2, 3 ]
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const iterate: (value: A, next: (value: A) => A) => Stream;
/**
* Constructs a stream from a range of integers, including both endpoints.
*
+ * **Details**
+ *
* If the provided `min` is greater than `max`, the stream will not emit any
* values.
*
- * @example
+ * **Example** (Creating a numeric range)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -1420,14 +1489,16 @@ export declare const iterate: (value: A, next: (value: A) => A) => Stream;
* Effect.runPromise(program)
* // Output: [ 1, 2, 3, 4, 5 ]
* ```
- * @since 4.0.0
- * @category Constructors
+ *
+ * @category constructors
+ * @since 2.0.0
*/
export declare const range: (min: number, max: number, chunkSize?: number) => Stream;
/**
* The stream that never produces any value or fails with any error.
*
- * @example
+ * **Example** (Creating a never-ending stream)
+ *
* ```ts
* import { Effect, Stream } from "effect"
*
@@ -1440,14 +1511,15 @@ export declare const range: (min: number, max: number, chunkSize?: number) => St
* // []
* ```
*
- * @since 4.0.0
- * @category Constructors
+ * @category constructors
+ * @since 2.0.0
*/
export declare const never: Stream;
/**
* Creates a stream produced from an `Effect`.
*
- * @example
+ * **Example** (Unwrapping a stream effect)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -1462,15 +1534,16 @@ export declare const never: Stream;
* // [1, 2, 3]
* ```
*
+ * @category constructors
* @since 2.0.0
- * @category Constructors
*/
export declare const unwrap: (effect: Effect.Effect, E, R>) => Stream>;
/**
* Runs a stream that requires `Scope` in a managed scope, ensuring its
* finalizers are run when the stream completes.
*
- * @example
+ * **Example** (Scoping a stream)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -1489,14 +1562,15 @@ export declare const unwrap: (effect: Effect.Effect(self: Stream) => Stream>;
/**
* Transforms the elements of this stream using the supplied function.
*
- * @example
+ * **Example** (Mapping stream values)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -1509,14 +1583,15 @@ export declare const scoped: (self: Stream) => Stream(f: (a: A, i: number) => B): (self: Stream) => Stream;
/**
* Transforms the elements of this stream using the supplied function.
*
- * @example
+ * **Example** (Mapping stream values)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -1549,15 +1625,16 @@ export declare const map: {
* // [ 1, 3, 5 ]
* ```
*
+ * @category mapping
* @since 2.0.0
- * @category Mapping
*/
(self: Stream, f: (a: A, i: number) => B): Stream;
};
/**
* Maps both the failure and success channels of a stream.
*
- * @example
+ * **Example** (Mapping both the failure and success channels of a stream)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -1586,14 +1663,15 @@ export declare const map: {
* // Output: [ "error: boom" ]
* ```
*
+ * @category mapping
* @since 2.0.0
- * @category Mapping
*/
export declare const mapBoth: {
/**
* Maps both the failure and success channels of a stream.
*
- * @example
+ * **Example** (Mapping both the failure and success channels of a stream)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -1622,8 +1700,8 @@ export declare const mapBoth: {
* // Output: [ "error: boom" ]
* ```
*
+ * @category mapping
* @since 2.0.0
- * @category Mapping
*/
(options: {
readonly onFailure: (e: E) => E2;
@@ -1632,7 +1710,8 @@ export declare const mapBoth: {
/**
* Maps both the failure and success channels of a stream.
*
- * @example
+ * **Example** (Mapping both the failure and success channels of a stream)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -1661,8 +1740,8 @@ export declare const mapBoth: {
* // Output: [ "error: boom" ]
* ```
*
+ * @category mapping
* @since 2.0.0
- * @category Mapping
*/
(self: Stream, options: {
readonly onFailure: (e: E) => E2;
@@ -1672,13 +1751,8 @@ export declare const mapBoth: {
/**
* Transforms each emitted chunk using the provided function, which receives the chunk and its index.
*
- * **Previously Known As**
- *
- * This API replaces the following from Effect 3.x:
+ * **Example** (Mapping stream chunks)
*
- * - `Stream.mapChunks`
- *
- * @example
* ```ts
* import { Array, Console, Effect, Stream } from "effect"
*
@@ -1695,20 +1769,15 @@ export declare const mapBoth: {
* // Output: [ 1, 2, 4, 5 ]
* ```
*
- * @since 2.0.0
- * @category Mapping
+ * @category mapping
+ * @since 4.0.0
*/
export declare const mapArray: {
/**
* Transforms each emitted chunk using the provided function, which receives the chunk and its index.
*
- * **Previously Known As**
- *
- * This API replaces the following from Effect 3.x:
+ * **Example** (Mapping stream chunks)
*
- * - `Stream.mapChunks`
- *
- * @example
* ```ts
* import { Array, Console, Effect, Stream } from "effect"
*
@@ -1725,20 +1794,15 @@ export declare const mapArray: {
* // Output: [ 1, 2, 4, 5 ]
* ```
*
- * @since 2.0.0
- * @category Mapping
+ * @category mapping
+ * @since 4.0.0
*/
(f: (a: Arr.NonEmptyReadonlyArray, i: number) => Arr.NonEmptyReadonlyArray): (self: Stream) => Stream;
/**
* Transforms each emitted chunk using the provided function, which receives the chunk and its index.
*
- * **Previously Known As**
- *
- * This API replaces the following from Effect 3.x:
+ * **Example** (Mapping stream chunks)
*
- * - `Stream.mapChunks`
- *
- * @example
* ```ts
* import { Array, Console, Effect, Stream } from "effect"
*
@@ -1755,15 +1819,21 @@ export declare const mapArray: {
* // Output: [ 1, 2, 4, 5 ]
* ```
*
- * @since 2.0.0
- * @category Mapping
+ * @category mapping
+ * @since 4.0.0
*/
(self: Stream, f: (a: Arr.NonEmptyReadonlyArray, i: number) => Arr.NonEmptyReadonlyArray): Stream;
};
/**
* Maps over elements of the stream with the specified effectful function.
*
- * @example
+ * **When to use**
+ *
+ * Use when each stream element transformation needs an Effect, service
+ * dependency, failure channel, or configured concurrency.
+ *
+ * **Example** (Effectfully mapping stream values)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -1791,14 +1861,20 @@ export declare const mapArray: {
* // [2, 4, 6]
* ```
*
+ * @category mapping
* @since 2.0.0
- * @category Mapping
*/
export declare const mapEffect: {
/**
* Maps over elements of the stream with the specified effectful function.
*
- * @example
+ * **When to use**
+ *
+ * Use when each stream element transformation needs an Effect, service
+ * dependency, failure channel, or configured concurrency.
+ *
+ * **Example** (Effectfully mapping stream values)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -1826,8 +1902,8 @@ export declare const mapEffect: {
* // [2, 4, 6]
* ```
*
+ * @category mapping
* @since 2.0.0
- * @category Mapping
*/
(f: (a: A, i: number) => Effect.Effect, options?: {
readonly concurrency?: number | "unbounded" | undefined;
@@ -1836,7 +1912,13 @@ export declare const mapEffect: {
/**
* Maps over elements of the stream with the specified effectful function.
*
- * @example
+ * **When to use**
+ *
+ * Use when each stream element transformation needs an Effect, service
+ * dependency, failure channel, or configured concurrency.
+ *
+ * **Example** (Effectfully mapping stream values)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -1864,8 +1946,8 @@ export declare const mapEffect: {
* // [2, 4, 6]
* ```
*
+ * @category mapping
* @since 2.0.0
- * @category Mapping
*/
(self: Stream, f: (a: A, i: number) => Effect.Effect, options?: {
readonly concurrency?: number | "unbounded" | undefined;
@@ -1875,7 +1957,13 @@ export declare const mapEffect: {
/**
* Flattens a stream of `Effect` values into a stream of their results.
*
- * @example
+ * **When to use**
+ *
+ * Use when stream elements already are effects and their successes should become
+ * stream elements while their failures enter the stream error channel.
+ *
+ * **Example** (Flattening a stream of Effect values into a stream of their results)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -1890,8 +1978,8 @@ export declare const mapEffect: {
* // Output: [1, 2, 3]
* ```
*
+ * @category mapping
* @since 2.0.0
- * @category Mapping
*/
export declare const flattenEffect: , any, any> | {
readonly concurrency?: number | "unbounded" | undefined;
@@ -1904,15 +1992,15 @@ export declare const flattenEffect: [Arg] extends [Stream, infer _E, infer _R>] ? Stream<_A, _EX | _E, _RX | _R> : (self: Stream, E, R>) => Stream;
/**
- * Effectfully maps over non-empty array chunks emitted by the stream.
+ * Maps over non-empty array chunks emitted by the stream effectfully.
*
- * **Previously Known As**
+ * **When to use**
*
- * This API replaces the following from Effect 3.x:
+ * Use when transformation needs to see and replace each non-empty emitted chunk
+ * effectfully instead of mapping individual stream elements.
*
- * - `Stream.mapChunksEffect`
+ * **Example** (Effectfully mapping stream chunks)
*
- * @example
* ```ts
* import { Array, Console, Effect, Stream } from "effect"
*
@@ -1931,20 +2019,20 @@ export declare const flattenEffect: (f: (a: Arr.NonEmptyReadonlyArray, i: number) => Effect.Effect, E2, R2>): (self: Stream) => Stream;
/**
- * Effectfully maps over non-empty array chunks emitted by the stream.
+ * Maps over non-empty array chunks emitted by the stream effectfully.
*
- * **Previously Known As**
+ * **When to use**
*
- * This API replaces the following from Effect 3.x:
+ * Use when transformation needs to see and replace each non-empty emitted chunk
+ * effectfully instead of mapping individual stream elements.
*
- * - `Stream.mapChunksEffect`
+ * **Example** (Effectfully mapping stream chunks)
*
- * @example
* ```ts
* import { Array, Console, Effect, Stream } from "effect"
*
@@ -1995,23 +2083,20 @@ export declare const mapArrayEffect: {
* // Output: [1, 2, 13, 14]
* ```
*
+ * @category mapping
* @since 4.0.0
- * @category Mapping
*/
(self: Stream, f: (a: Arr.NonEmptyReadonlyArray, i: number) => Effect.Effect, E2, R2>): Stream;
};
/**
* Lifts failures and successes into a `Result`, yielding a stream that cannot fail.
*
- * The stream ends after the first failure, emitting a `Result.fail` value.
- *
- * **Previously Known As:**
+ * **Details**
*
- * This API replaces the following from Effect 3.x:
+ * The stream ends after the first failure, emitting a `Result.fail` value.
*
- * - `Stream.either`
+ * **Example** (Converting failures to results)
*
- * @example
* ```ts
* import { Console, Effect, Result, Stream } from "effect"
*
@@ -2032,14 +2117,15 @@ export declare const mapArrayEffect: {
* // Output: [ "success: 1", "success: 2", "failure: boom" ]
* ```
*
+ * @category error handling
* @since 4.0.0
- * @category Error Handling
*/
export declare const result: (self: Stream) => Stream, never, R>;
/**
* Runs the provided effect for each element while preserving the elements.
*
- * @example
+ * **Example** (Tapping stream values)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -2065,14 +2151,15 @@ export declare const result: (self: Stream) => Stream(f: (a: NoInfer) => Effect.Effect, options?: {
readonly concurrency?: number | "unbounded" | undefined;
@@ -2107,7 +2194,8 @@ export declare const tap: {
/**
* Runs the provided effect for each element while preserving the elements.
*
- * @example
+ * **Example** (Tapping stream values)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -2133,8 +2221,8 @@ export declare const tap: {
* // [ 2, 4, 6 ]
* ```
*
+ * @category sequencing
* @since 2.0.0
- * @category Sequencing
*/
(self: Stream, f: (a: NoInfer) => Effect.Effect, options?: {
readonly concurrency?: number | "unbounded" | undefined;
@@ -2143,7 +2231,8 @@ export declare const tap: {
/**
* Returns a stream that effectfully "peeks" at elements and failures.
*
- * @example
+ * **Example** (Tapping values and errors)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -2168,14 +2257,15 @@ export declare const tap: {
* // [ 1, 2, 3 ]
* ```
*
+ * @category sequencing
* @since 2.0.0
- * @category Sequencing
*/
export declare const tapBoth: {
/**
* Returns a stream that effectfully "peeks" at elements and failures.
*
- * @example
+ * **Example** (Tapping values and errors)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -2200,8 +2290,8 @@ export declare const tapBoth: {
* // [ 1, 2, 3 ]
* ```
*
+ * @category sequencing
* @since 2.0.0
- * @category Sequencing
*/
(options: {
readonly onElement: (a: NoInfer) => Effect.Effect;
@@ -2211,7 +2301,8 @@ export declare const tapBoth: {
/**
* Returns a stream that effectfully "peeks" at elements and failures.
*
- * @example
+ * **Example** (Tapping values and errors)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -2236,8 +2327,8 @@ export declare const tapBoth: {
* // [ 1, 2, 3 ]
* ```
*
+ * @category sequencing
* @since 2.0.0
- * @category Sequencing
*/
(self: Stream, options: {
readonly onElement: (a: NoInfer) => Effect.Effect;
@@ -2246,10 +2337,10 @@ export declare const tapBoth: {
}): Stream;
};
/**
- * Sends all elements emitted by this stream to the specified sink in addition
- * to emitting them.
+ * Runs a sink for all stream elements while still emitting them downstream.
+ *
+ * **Example** (Tapping values with a sink)
*
- * @example
* ```ts
* import { Console, Effect, Ref, Sink, Stream } from "effect"
*
@@ -2272,15 +2363,15 @@ export declare const tapBoth: {
* // Output: [1, 2, 3]
* ```
*
+ * @category sequencing
* @since 2.0.0
- * @category Sequencing
*/
export declare const tapSink: {
/**
- * Sends all elements emitted by this stream to the specified sink in addition
- * to emitting them.
+ * Runs a sink for all stream elements while still emitting them downstream.
+ *
+ * **Example** (Tapping values with a sink)
*
- * @example
* ```ts
* import { Console, Effect, Ref, Sink, Stream } from "effect"
*
@@ -2303,15 +2394,15 @@ export declare const tapSink: {
* // Output: [1, 2, 3]
* ```
*
+ * @category sequencing
* @since 2.0.0
- * @category Sequencing
*/
(sink: Sink.Sink): (self: Stream) => Stream;
/**
- * Sends all elements emitted by this stream to the specified sink in addition
- * to emitting them.
+ * Runs a sink for all stream elements while still emitting them downstream.
+ *
+ * **Example** (Tapping values with a sink)
*
- * @example
* ```ts
* import { Console, Effect, Ref, Sink, Stream } from "effect"
*
@@ -2334,15 +2425,23 @@ export declare const tapSink: {
* // Output: [1, 2, 3]
* ```
*
+ * @category sequencing
* @since 2.0.0
- * @category Sequencing
*/
(self: Stream, sink: Sink.Sink): Stream;
};
/**
- * Maps each element to a stream and concatenates the results in order.
+ * Maps each element to a stream and flattens the resulting streams.
+ *
+ * **Details**
+ *
+ * With the default sequential concurrency, inner streams are concatenated in
+ * input order. When `concurrency` is greater than `1` or `"unbounded"`,
+ * multiple inner streams may run at the same time and their outputs are merged
+ * as they arrive.
+ *
+ * **Example** (FlatMapping stream values)
*
- * @example
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -2358,14 +2457,22 @@ export declare const tapSink: {
* // Output: [ 1, 2, 2, 4, 3, 6 ]
* ```
*
+ * @category mapping
* @since 2.0.0
- * @category Mapping
*/
export declare const flatMap: {
/**
- * Maps each element to a stream and concatenates the results in order.
+ * Maps each element to a stream and flattens the resulting streams.
+ *
+ * **Details**
+ *
+ * With the default sequential concurrency, inner streams are concatenated in
+ * input order. When `concurrency` is greater than `1` or `"unbounded"`,
+ * multiple inner streams may run at the same time and their outputs are merged
+ * as they arrive.
+ *
+ * **Example** (FlatMapping stream values)
*
- * @example
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -2381,17 +2488,25 @@ export declare const flatMap: {
* // Output: [ 1, 2, 2, 4, 3, 6 ]
* ```
*
+ * @category mapping
* @since 2.0.0
- * @category Mapping
*/
(f: (a: A) => Stream, options?: {
readonly concurrency?: number | "unbounded" | undefined;
readonly bufferSize?: number | undefined;
} | undefined): (self: Stream) => Stream;
/**
- * Maps each element to a stream and concatenates the results in order.
+ * Maps each element to a stream and flattens the resulting streams.
+ *
+ * **Details**
+ *
+ * With the default sequential concurrency, inner streams are concatenated in
+ * input order. When `concurrency` is greater than `1` or `"unbounded"`,
+ * multiple inner streams may run at the same time and their outputs are merged
+ * as they arrive.
+ *
+ * **Example** (FlatMapping stream values)
*
- * @example
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -2407,8 +2522,8 @@ export declare const flatMap: {
* // Output: [ 1, 2, 2, 4, 3, 6 ]
* ```
*
+ * @category mapping
* @since 2.0.0
- * @category Mapping
*/
(self: Stream, f: (a: A) => Stream, options?: {
readonly concurrency?: number | "unbounded" | undefined;
@@ -2419,7 +2534,8 @@ export declare const flatMap: {
* Switches to the latest stream produced by the mapping function, interrupting
* the previous stream when a new element arrives.
*
- * @example
+ * **Example** (Switching to the latest stream)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -2435,15 +2551,16 @@ export declare const flatMap: {
* })
* ```
*
+ * @category sequencing
* @since 4.0.0
- * @category Sequencing
*/
export declare const switchMap: {
/**
* Switches to the latest stream produced by the mapping function, interrupting
* the previous stream when a new element arrives.
*
- * @example
+ * **Example** (Switching to the latest stream)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -2459,8 +2576,8 @@ export declare const switchMap: {
* })
* ```
*
+ * @category sequencing
* @since 4.0.0
- * @category Sequencing
*/
(f: (a: A) => Stream, options?: {
readonly concurrency?: number | "unbounded" | undefined;
@@ -2470,7 +2587,8 @@ export declare const switchMap: {
* Switches to the latest stream produced by the mapping function, interrupting
* the previous stream when a new element arrives.
*
- * @example
+ * **Example** (Switching to the latest stream)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -2486,8 +2604,8 @@ export declare const switchMap: {
* })
* ```
*
+ * @category sequencing
* @since 4.0.0
- * @category Sequencing
*/
(self: Stream, f: (a: A) => Stream, options?: {
readonly concurrency?: number | "unbounded" | undefined;
@@ -2495,10 +2613,17 @@ export declare const switchMap: {
} | undefined): Stream;
};
/**
- * Flattens a stream of streams into a single stream by concatenating the
- * inner streams in strict order.
+ * Flattens a stream of streams into a single stream.
+ *
+ * **Details**
+ *
+ * With the default sequential concurrency, inner streams are concatenated in
+ * strict order. When `concurrency` is greater than `1` or `"unbounded"`,
+ * multiple inner streams may run at the same time and their outputs are merged
+ * as they arrive.
+ *
+ * **Example** (Flattening nested streams)
*
- * @example
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -2517,8 +2642,8 @@ export declare const switchMap: {
* // Output: [ 1, 2, 3, 4, 5, 6 ]
* ```
*
+ * @category mapping
* @since 2.0.0
- * @category Mapping
*/
export declare const flatten: , any, any> | {
readonly concurrency?: number | "unbounded" | undefined;
@@ -2533,13 +2658,8 @@ export declare const flatten: , any, an
/**
* Flattens a stream of non-empty arrays into a stream of elements.
*
- * **Previously Known As**
- *
- * This API replaces the following from Effect 3.x:
- *
- * - `Stream.flattenChunks`
+ * **Example** (Flattening a stream of non-empty arrays into a stream of elements)
*
- * @example
* ```ts
* import { Array, Console, Effect, Stream } from "effect"
*
@@ -2554,14 +2674,15 @@ export declare const flatten: , any, an
* // Output: [ 1, 2, 3 ]
* ```
*
+ * @category sequencing
* @since 4.0.0
- * @category Sequencing
*/
export declare const flattenArray: (self: Stream, E, R>) => Stream;
/**
* Converts this stream to one that runs its effects but emits no elements.
*
- * @example
+ * **Example** (Draining stream values)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -2574,15 +2695,16 @@ export declare const flattenArray: (self: Stream(self: Stream) => Stream;
/**
* Runs the provided stream in the background while this stream runs, interrupting it
* when this stream completes and failing if the background stream fails or defects.
*
- * @example
+ * **Example** (Draining a stream in the background)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -2602,15 +2724,16 @@ export declare const drain: (self: Stream) => Stream(that: Stream): (self: Stream) => Stream;
/**
* Runs the provided stream in the background while this stream runs, interrupting it
* when this stream completes and failing if the background stream fails or defects.
*
- * @example
+ * **Example** (Draining a stream in the background)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -2658,15 +2782,16 @@ export declare const drainFork: {
* // Output: [ 1, 2 ]
* ```
*
+ * @category sequencing
* @since 2.0.0
- * @category Sequencing
*/
(self: Stream, that: Stream): Stream;
};
/**
* Repeats the entire stream according to the provided schedule.
*
- * @example
+ * **Example** (Repeating a stream on a schedule)
+ *
* ```ts
* import { Console, Effect, Schedule, Stream } from "effect"
*
@@ -2683,14 +2808,15 @@ export declare const drainFork: {
* // Output: [ 1, 1, 1, 1, 1 ]
* ```
*
+ * @category sequencing
* @since 2.0.0
- * @category Sequencing
*/
export declare const repeat: {
/**
* Repeats the entire stream according to the provided schedule.
*
- * @example
+ * **Example** (Repeating a stream on a schedule)
+ *
* ```ts
* import { Console, Effect, Schedule, Stream } from "effect"
*
@@ -2707,14 +2833,15 @@ export declare const repeat: {
* // Output: [ 1, 1, 1, 1, 1 ]
* ```
*
+ * @category sequencing
* @since 2.0.0
- * @category Sequencing
*/
(schedule: Schedule.Schedule | (($: (_: Schedule.Schedule) => Schedule.Schedule) => Schedule.Schedule)): (self: Stream) => Stream;
/**
* Repeats the entire stream according to the provided schedule.
*
- * @example
+ * **Example** (Repeating a stream on a schedule)
+ *
* ```ts
* import { Console, Effect, Schedule, Stream } from "effect"
*
@@ -2731,15 +2858,16 @@ export declare const repeat: {
* // Output: [ 1, 1, 1, 1, 1 ]
* ```
*
+ * @category sequencing
* @since 2.0.0
- * @category Sequencing
*/
(self: Stream, schedule: Schedule.Schedule | (($: (_: Schedule.Schedule) => Schedule.Schedule) => Schedule.Schedule)): Stream;
};
/**
- * Spaces the stream's elements according to the provided `schedule`.
+ * Schedules the stream's elements according to the provided schedule.
+ *
+ * **Example** (Scheduling stream elements)
*
- * @example
* ```ts
* import { Console, Effect, Schedule, Stream } from "effect"
*
@@ -2756,14 +2884,15 @@ export declare const repeat: {
* // Output: [ 1, 2, 3 ]
* ```
*
+ * @category rate limiting
* @since 2.0.0
- * @category Rate Limiting
*/
export declare const schedule: {
/**
- * Spaces the stream's elements according to the provided `schedule`.
+ * Schedules the stream's elements according to the provided schedule.
+ *
+ * **Example** (Scheduling stream elements)
*
- * @example
* ```ts
* import { Console, Effect, Schedule, Stream } from "effect"
*
@@ -2780,14 +2909,15 @@ export declare const schedule: {
* // Output: [ 1, 2, 3 ]
* ```
*
+ * @category rate limiting
* @since 2.0.0
- * @category Rate Limiting
*/
(schedule: Schedule.Schedule, E2, R2>): (self: Stream) => Stream;
/**
- * Spaces the stream's elements according to the provided `schedule`.
+ * Schedules the stream's elements according to the provided schedule.
+ *
+ * **Example** (Scheduling stream elements)
*
- * @example
* ```ts
* import { Console, Effect, Schedule, Stream } from "effect"
*
@@ -2804,15 +2934,16 @@ export declare const schedule: {
* // Output: [ 1, 2, 3 ]
* ```
*
+ * @category rate limiting
* @since 2.0.0
- * @category Rate Limiting
*/
(self: Stream, schedule: Schedule.Schedule, E2, R2>): Stream;
};
/**
* Ends the stream if it does not produce a value within the specified duration.
*
- * @example
+ * **Example** (Timing out a stream)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -2829,14 +2960,15 @@ export declare const schedule: {
* // Output: [ 1 ]
* ```
*
+ * @category rate limiting
* @since 2.0.0
- * @category Rate Limiting
*/
export declare const timeout: {
/**
* Ends the stream if it does not produce a value within the specified duration.
*
- * @example
+ * **Example** (Timing out a stream)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -2853,14 +2985,15 @@ export declare const timeout: {
* // Output: [ 1 ]
* ```
*
+ * @category rate limiting
* @since 2.0.0
- * @category Rate Limiting
*/
(duration: Duration.Input): (self: Stream) => Stream;
/**
* Ends the stream if it does not produce a value within the specified duration.
*
- * @example
+ * **Example** (Timing out a stream)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -2877,27 +3010,87 @@ export declare const timeout: {
* // Output: [ 1 ]
* ```
*
+ * @category rate limiting
* @since 2.0.0
- * @category Rate Limiting
*/
(self: Stream, duration: Duration.Input): Stream;
};
/**
- * @since 2.0.0
- * @category Rate Limiting
+ * 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.
+ *
+ * @see {@link timeout} for ending the stream instead of switching to a fallback stream
+ *
+ * @category rate limiting
+ * @since 4.0.0
*/
export declare const timeoutOrElse: {
/**
- * @since 2.0.0
- * @category Rate Limiting
+ * 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.
+ *
+ * @see {@link timeout} for ending the stream instead of switching to a fallback stream
+ *
+ * @category rate limiting
+ * @since 4.0.0
*/
(options: {
readonly duration: Duration.Input;
readonly orElse: () => Stream;
}): (self: Stream) => Stream;
/**
- * @since 2.0.0
- * @category Rate Limiting
+ * 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.
+ *
+ * @see {@link timeout} for ending the stream instead of switching to a fallback stream
+ *
+ * @category rate limiting
+ * @since 4.0.0
*/
(self: Stream, options: {
readonly duration: Duration.Input;
@@ -2908,9 +3101,8 @@ export declare const timeoutOrElse: {
* Repeats each element of the stream according to the provided schedule,
* including the original emission.
*
- * @since 2.0.0
- * @category Sequencing
- * @example
+ * **Example** (Repeating stream elements)
+ *
* ```ts
* import { Console, Effect, Schedule, Stream } from "effect"
*
@@ -2925,15 +3117,17 @@ export declare const timeoutOrElse: {
* Effect.runPromise(program)
* // Output: [ "A", "A", "B", "B", "C", "C" ]
* ```
+ *
+ * @category sequencing
+ * @since 2.0.0
*/
export declare const repeatElements: {
/**
* Repeats each element of the stream according to the provided schedule,
* including the original emission.
*
- * @since 2.0.0
- * @category Sequencing
- * @example
+ * **Example** (Repeating stream elements)
+ *
* ```ts
* import { Console, Effect, Schedule, Stream } from "effect"
*
@@ -2948,15 +3142,17 @@ export declare const repeatElements: {
* Effect.runPromise(program)
* // Output: [ "A", "A", "B", "B", "C", "C" ]
* ```
+ *
+ * @category sequencing
+ * @since 2.0.0
*/
(schedule: Schedule.Schedule): (self: Stream) => Stream;
/**
* Repeats each element of the stream according to the provided schedule,
* including the original emission.
*
- * @since 2.0.0
- * @category Sequencing
- * @example
+ * **Example** (Repeating stream elements)
+ *
* ```ts
* import { Console, Effect, Schedule, Stream } from "effect"
*
@@ -2971,13 +3167,17 @@ export declare const repeatElements: {
* Effect.runPromise(program)
* // Output: [ "A", "A", "B", "B", "C", "C" ]
* ```
+ *
+ * @category sequencing
+ * @since 2.0.0
*/
(self: Stream, schedule: Schedule.Schedule): Stream;
};
/**
* Repeats this stream forever.
*
- * @example
+ * **Example** (Repeating a stream forever)
+ *
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -2995,20 +3195,15 @@ export declare const repeatElements: {
* // Output: [ "A", "B", "A", "B", "A" ]
* ```
*
+ * @category sequencing
* @since 2.0.0
- * @category Sequencing
*/
export declare const forever: (self: Stream) => Stream;
/**
- * Submerges the iterables emitted by this stream into the stream's structure.
+ * Flattens the iterables emitted by this stream into the stream's structure.
*
- * **Previously Known As**
+ * **Example** (Flattening iterable values)
*
- * This API replaces the following from Effect 3.x:
- *
- * - `Stream.flattenIterables`
- *
- * @example
* ```ts
* import { Console, Effect, Stream } from "effect"
*
@@ -3022,15 +3217,16 @@ export declare const forever: (self: Stream) => Stream(self: Stream, E, R>) => Stream