diff --git "a/.opencode/node_modules/effect/dist/Channel.d.ts" "b/.opencode/node_modules/effect/dist/Channel.d.ts" --- "a/.opencode/node_modules/effect/dist/Channel.d.ts" +++ "b/.opencode/node_modules/effect/dist/Channel.d.ts" @@ -1,58 +1,11 @@ /** - * The `Channel` module provides a powerful abstraction for bi-directional communication - * and streaming operations. A `Channel` is a nexus of I/O operations that supports both - * reading and writing, forming the foundation for Effect's Stream and Sink abstractions. + * Provides low-level building blocks for streaming data through Effect. * - * ## What is a Channel? - * - * A `Channel` represents: - * - **OutElem**: The type of elements the channel outputs - * - **OutErr**: The type of errors the channel can produce - * - **OutDone**: The type of the final value when the channel completes - * - **InElem**: The type of elements the channel reads - * - **InErr**: The type of errors the channel can receive - * - **InDone**: The type of the final value from upstream - * - **Env**: The environment/context required by the channel - * - * ## Key Features - * - * - **Bi-directional**: Channels can both read and write - * - **Composable**: Channels can be piped, sequenced, and concatenated - * - **Resource-safe**: Automatic cleanup and resource management - * - **Error-handling**: Built-in error propagation and handling - * - **Concurrent**: Support for concurrent operations - * - * ## Composition Patterns - * - * 1. **Piping**: Connect channels where output of one becomes input of another - * 2. **Sequencing**: Use the result of one channel to create another - * 3. **Concatenating**: Combine multiple channels into a single channel - * - * @example - * ```ts - * import { Channel } from "effect" - * - * // Simple channel that outputs numbers - * const numberChannel = Channel.succeed(42) - * - * // Transform channel that doubles values - * const doubleChannel = Channel.map(numberChannel, (n) => n * 2) - * - * // Running the channel would output: 84 - * ``` - * - * @example - * ```ts - * import { Channel } from "effect" - * - * // Channel from an array of values - * const arrayChannel = Channel.fromArray([1, 2, 3, 4, 5]) - * - * // Transform the channel by mapping over values - * const transformedChannel = Channel.map(arrayChannel, (n) => n * 2) - * - * // This channel will output: 2, 4, 6, 8, 10 - * ``` + * A `Channel` can read input elements, write output elements, fail with a typed + * error, and finish with a typed result while managing resources safely. + * Streams and sinks are built on channels, so most application code uses those + * higher-level modules instead. This module is useful when implementing stream + * operators or specialized streaming workflows. * * @since 2.0.0 */ @@ -79,19 +32,25 @@ import { ParentSpan, type SpanOptions } from "./Tracer.ts"; import type * as Types from "./Types.ts"; import type * as Unify from "./Unify.ts"; /** + * String literal type used as the unique brand for `Channel` values. + * + * @category type IDs * @since 4.0.0 - * @category Type Identifiers */ export type TypeId = "~effect/Channel"; /** + * Runtime identifier stored on `Channel` values and used by `isChannel` to + * recognize them. + * + * @category type IDs * @since 4.0.0 - * @category Type Identifiers */ export declare const TypeId: TypeId; /** - * Tests if a value is a `Channel`. + * Checks whether a value is a `Channel`. + * + * **Example** (Checking for channels) * - * @example * ```ts * import { Channel } from "effect" * @@ -110,6 +69,8 @@ export declare const isChannel: (u: unknown) => u is Channel u is Channel u is Channel * ``` * - * @since 2.0.0 * @category models + * @since 2.0.0 */ export interface Channel extends Variance, Pipeable { [Unify.typeSymbol]?: unknown; @@ -158,8 +120,16 @@ export interface Channel A[Unify.typeSymbol] extends Channel | infer _ ? Channel : never; } /** + * Marker used by `Unify` while resolving `Channel` values. + * + * **Details** + * + * It prevents the inherited `Effect` unifier from being selected when the + * channel-specific unifier should preserve `Channel` input, output, and + * environment type parameters. Users normally do not need to reference this + * interface directly. + * * @category models * @since 2.0.0 */ @@ -177,15 +156,33 @@ type TagsWithReason = { [T in Types.Tags]: Types.ReasonTags> extends never ? never : T; }[Types.Tags]; /** - * @since 2.0.0 + * Phantom variance marker for the type parameters of `Channel`. + * + * **Details** + * + * Output element, output error, output done, and environment types are + * covariant. Input element, input error, and input done types are + * contravariant. This is type-level machinery and is not used directly at + * runtime. + * * @category models + * @since 2.0.0 */ export interface Variance { readonly [TypeId]: VarianceStruct; } /** - * @since 2.0.0 + * Structural encoding used by `Variance` to record each `Channel` type + * parameter's variance. + * + * **Details** + * + * The `_OutElem`, `_OutErr`, `_OutDone`, and `_Env` fields are covariant; the + * `_InElem`, `_InErr`, and `_InDone` fields are contravariant. Users normally + * do not need to reference this interface directly. + * * @category models + * @since 2.0.0 */ export interface VarianceStruct { _Env: Types.Covariant; @@ -199,7 +196,8 @@ export interface VarianceStruct(effect: * pulls, but also provides a forked scope that closes when the resulting * Channel completes. * - * @since 4.0.0 + * **When to use** + * + * Use when building channels that require scoped resource lifecycle management, + * providing both the channel scope and a forked scope that automatically closes + * when the channel completes. + * + * @see {@link fromTransform} for a simpler transformation without a forked scope * @category constructors + * @since 4.0.0 */ export declare const fromTransformBracket: (f: (upstream: Pull.Pull, scope: Scope.Scope, forkedScope: Scope.Scope) => Effect.Effect, EX, Env>) => Channel | EX, OutDone, InElem, InErr, InDone, Env | EnvX>; /** * Converts a `Channel` back to its underlying transformation function. * - * @example + * **Example** (Extracting channel transforms) + * * ```ts * import { Channel } from "effect" * @@ -280,7 +288,8 @@ export declare const toTransform: (f: (queue: Queue.Queue) => Effect.Effect, options?: { readonly bufferSize?: number | undefined; @@ -317,7 +327,8 @@ export declare const callback: (f: (queue: Queue.Queue< /** * Creates a `Channel` that interacts with a callback function using a queue, emitting arrays. * - * @example + * **Example** (Creating array channels from callbacks) + * * ```ts * import { Channel, Effect, Queue } from "effect" * @@ -338,7 +349,8 @@ export declare const callbackArray: (f: (queue: Queue.Q /** * Creates a `Channel` that lazily evaluates to another channel. * - * @example + * **Example** (Suspending channel creation) + * * ```ts * import { Channel } from "effect" * @@ -351,9 +363,17 @@ export declare const callbackArray: (f: (queue: Queue.Q */ export declare const suspend: (evaluate: LazyArg>) => Channel; /** - * Creates a `Channel` with resource management using acquire-use-release pattern. + * Acquires a resource, uses it to build a `Channel`, and guarantees that + * `release` runs with the channel's `Exit` when the channel completes, fails, + * or is interrupted. + * + * **Details** + * + * Acquisition is uninterruptible. If acquisition fails, `use` is not run and + * `release` is not registered. + * + * **Example** (Managing resources with acquire-use-release) * - * @example * ```ts * import { Channel, Effect } from "effect" * @@ -369,9 +389,17 @@ export declare const suspend: (acquire: Effect.Effect, use: (a: A) => Channel, release: (a: A, exit: Exit.Exit) => Effect.Effect) => Channel; /** - * Creates a `Channel` with resource management using acquire-release pattern. + * Acquires a resource, emits the acquired value as a single channel element, + * and registers `release` in the channel scope. + * + * **Details** + * + * The release action runs when the channel scope closes and receives the scope + * exit. If acquisition fails, no element is emitted and `release` is not + * registered. + * + * **Example** (Managing resources with acquire-release) * - * @example * ```ts * import { Channel, Effect } from "effect" * @@ -382,13 +410,21 @@ export declare const acquireUseRelease: (release: (z: Z, e: Exit.Exit) => Effect.Effect): (self: Effect.Effect) => Channel; /** - * Creates a `Channel` with resource management using acquire-release pattern. + * Acquires a resource, emits the acquired value as a single channel element, + * and registers `release` in the channel scope. + * + * **Details** + * + * The release action runs when the channel scope closes and receives the scope + * exit. If acquisition fails, no element is emitted and `release` is not + * registered. + * + * **Example** (Managing resources with acquire-release) * - * @example * ```ts * import { Channel, Effect } from "effect" * @@ -416,14 +460,15 @@ export declare const acquireRelease: { * ``` * * @category constructors - * @since 2.0.0 + * @since 4.0.0 */ (self: Effect.Effect, release: (z: Z, e: Exit.Exit) => Effect.Effect): Channel; }; /** * Creates a `Channel` from an iterator. * - * @example + * **Example** (Creating channels from iterators) + * * ```ts * import { Channel } from "effect" * @@ -433,13 +478,14 @@ export declare const acquireRelease: { * ``` * * @category constructors - * @since 2.0.0 + * @since 4.0.0 */ export declare const fromIterator: (iterator: LazyArg>) => Channel; /** * Creates a `Channel` that emits all elements from an array. * - * @example + * **Example** (Creating channels from arrays) + * * ```ts * import { Channel } from "effect" * @@ -448,13 +494,14 @@ export declare const fromIterator: (iterator: LazyArg>) => * ``` * * @category constructors - * @since 2.0.0 + * @since 4.0.0 */ export declare const fromArray: (array: ReadonlyArray) => Channel; /** * Creates a `Channel` that emits all elements from a chunk. * - * @example + * **Example** (Creating channels from chunks) + * * ```ts * import { Channel, Chunk } from "effect" * @@ -464,13 +511,14 @@ export declare const fromArray: (array: ReadonlyArray) => Channel; * ``` * * @category constructors - * @since 2.0.0 + * @since 4.0.0 */ export declare const fromChunk: (chunk: Chunk.Chunk) => Channel; /** * Creates a `Channel` from an iterator that emits arrays of elements. * - * @example + * **Example** (Batching iterator output) + * * ```ts * import { Channel } from "effect" * @@ -491,7 +539,8 @@ export declare const fromChunk: (chunk: Chunk.Chunk) => Channel; * // This will emit arrays: [0, 1], [2], then complete with "finished" * ``` * - * @example + * **Example** (Batching generator output) + * * ```ts * import { Channel } from "effect" * @@ -508,14 +557,15 @@ export declare const fromChunk: (chunk: Chunk.Chunk) => Channel; * // Emits: [0, 1, 1], [2, 3], then completes * ``` * - * @since 2.0.0 * @category constructors + * @since 4.0.0 */ export declare const fromIteratorArray: (iterator: LazyArg>, chunkSize?: number) => Channel, never, L>; /** * Creates a `Channel` that emits all elements from an iterable. * - * @example + * **Example** (Creating channels from iterables) + * * ```ts * import { Channel } from "effect" * @@ -525,13 +575,14 @@ export declare const fromIteratorArray: (iterator: LazyArg> * ``` * * @category constructors - * @since 2.0.0 + * @since 4.0.0 */ export declare const fromIterable: (iterable: Iterable) => Channel; /** * Creates a `Channel` that emits arrays of elements from an iterable. * - * @example + * **Example** (Batching iterable output) + * * ```ts * import { Channel } from "effect" * @@ -541,13 +592,14 @@ export declare const fromIterable: (iterable: Iterable) => Channel(iterable: Iterable, chunkSize?: number) => Channel, never, L>; /** * Creates a `Channel` that emits a single value and then ends. * - * @example + * **Example** (Creating channels that succeed) + * * ```ts * import { Channel } from "effect" * @@ -562,7 +614,8 @@ export declare const succeed: (value: A) => Channel; /** * Creates a `Channel` that immediately ends with the specified value. * - * @example + * **Example** (Ending with a value) + * * ```ts * import { Channel } from "effect" * @@ -584,12 +637,18 @@ export declare const endSync: (evaluate: LazyArg) => Channel Math.random()) - * // Emits a random number computed when the channel runs + * let requests = 0 + * + * const channel = Channel.sync(() => { + * requests += 1 + * return `request-${requests}` + * }) + * // Emits "request-1" when the channel runs for the first time * ``` * * @category constructors @@ -597,9 +656,10 @@ export declare const endSync: (evaluate: LazyArg) => Channel(evaluate: LazyArg) => Channel; /** - * Represents an Channel that emits no elements + * Represents a `Channel` that emits no elements. + * + * **Example** (Using empty channels) * - * @example * ```ts * import { Channel } from "effect" * @@ -615,14 +675,15 @@ export declare const sync: (evaluate: LazyArg) => Channel; * shouldEmit ? Channel.succeed("data") : Channel.empty * ``` * - * @since 2.0.0 * @category constructors + * @since 4.0.0 */ export declare const empty: Channel; /** - * Represents an Channel that never completes + * Represents a `Channel` that never completes. + * + * **Example** (Using non-terminating channels) * - * @example * ```ts * import { Channel } from "effect" * @@ -640,14 +701,15 @@ export declare const empty: Channel; * shouldComplete ? Channel.succeed("done") : Channel.never * ``` * - * @since 2.0.0 * @category constructors + * @since 2.0.0 */ export declare const never: Channel; /** * Constructs a channel that fails immediately with the specified error. * - * @example + * **Example** (Failing with an error) + * * ```ts * import { Channel } from "effect" * @@ -670,15 +732,21 @@ export declare const never: Channel; * ) * ``` * - * @since 2.0.0 * @category constructors + * @since 2.0.0 */ export declare const fail: (error: E) => Channel; /** * Constructs a channel that fails immediately with the specified lazily * evaluated error. * - * @example + * **When to use** + * + * Use when the error value should be computed each time the channel runs instead + * of when the channel is constructed. + * + * **Example** (Failing with a lazy error) + * * ```ts * import { Channel } from "effect" * @@ -689,25 +757,33 @@ export declare const fail: (error: E) => Channel; * }) * * // The error computation is deferred until the channel runs - * const conditionalError = Channel.failSync(() => - * Math.random() > 0.5 ? "Error A" : "Error B" - * ) + * let attempts = 0 + * const conditionalError = Channel.failSync(() => { + * attempts += 1 + * return `Error after attempt ${attempts}` + * }) * * // Use with expensive error construction * const expensiveError = Channel.failSync(() => { - * const timestamp = Date.now() - * return new Error(`Failed at: ${timestamp}`) + * const requestId = "request-123" + * return new Error(`Failed while processing ${requestId}`) * }) * ``` * - * @since 2.0.0 * @category constructors + * @since 2.0.0 */ export declare const failSync: (evaluate: LazyArg) => Channel; /** * Constructs a channel that fails immediately with the specified `Cause`. * - * @example + * **When to use** + * + * Use when the channel failure must preserve a full `Cause`, such as defects, + * interruptions, or combined failures. + * + * **Example** (Failing with causes) + * * ```ts * import { Cause, Channel } from "effect" * @@ -724,39 +800,42 @@ export declare const failSync: (evaluate: LazyArg) => Channel(cause: Cause.Cause) => Channel; /** * Constructs a channel that fails immediately with the specified lazily * evaluated `Cause`. * - * @example + * **Example** (Failing with lazy causes) + * * ```ts * import { Cause, Channel } from "effect" * * // Create a channel that fails with a lazily computed cause + * let attempts = 0 * const failedChannel = Channel.failCauseSync(() => { - * const errorType = Math.random() > 0.5 ? "A" : "B" - * return Cause.fail(`Runtime error ${errorType}`) + * attempts += 1 + * return Cause.fail(`Runtime error after attempt ${attempts}`) * }) * * // Create a channel with die cause computation * const dieCauseChannel = Channel.failCauseSync(() => { - * const timestamp = Date.now() - * return Cause.die(`Error at ${timestamp}`) + * const operation = "load-profile" + * return Cause.die(`Unexpected defect during ${operation}`) * }) * ``` * - * @since 2.0.0 * @category constructors + * @since 2.0.0 */ export declare const failCauseSync: (evaluate: LazyArg>) => Channel; /** * Constructs a channel that fails immediately with the specified defect. * - * @example + * **Example** (Dying with defects) + * * ```ts * import { Channel } from "effect" * @@ -773,14 +852,15 @@ export declare const failCauseSync: (evaluate: LazyArg>) => Ch * }) * ``` * - * @since 2.0.0 * @category constructors + * @since 4.0.0 */ export declare const die: (defect: unknown) => Channel; /** - * Use an effect to write a single value to the channel. + * Uses an effect to write a single value to the channel. + * + * **Example** (Creating channels from effects) * - * @example * ```ts * import { Channel, Data, Effect } from "effect" * @@ -810,31 +890,47 @@ export declare const die: (defect: unknown) => Channel; * ) * ``` * - * @since 2.0.0 * @category constructors + * @since 2.0.0 */ export declare const fromEffect: (effect: Effect.Effect) => Channel, void, unknown, unknown, unknown, R>; /** - * @since 4.0.0 + * Creates a channel that evaluates an effect and uses its successful value as + * the channel's done value without emitting any output elements. + * + * **Details** + * + * If the effect fails, the channel fails with the effect's error. + * * @category constructors + * @since 4.0.0 */ export declare const fromEffectDone: (effect: Effect.Effect) => Channel, A, unknown, unknown, unknown, R>; /** - * Use an effect and discard its result. + * Uses an effect and discards its result. * - * @since 4.0.0 * @category constructors + * @since 4.0.0 */ export declare const fromEffectDrain: (effect: Effect.Effect) => Channel; /** - * @since 4.0.0 + * Creates a channel from an effect that produces a `Take`. + * + * **Details** + * + * A successful `Take` emits a non-empty array of output elements. A failed + * `Take` fails the channel. A done `Take` completes the channel with its done + * value. + * * @category constructors + * @since 4.0.0 */ export declare const fromEffectTake: (effect: Effect.Effect, E2, R>) => Channel, E | E2, Done, unknown, unknown, unknown, R>; /** - * Create a channel from a queue + * Creates a channel from a queue. + * + * **Example** (Creating channels from queues) * - * @example * ```ts * import { Channel, Data, Effect, Queue } from "effect" * @@ -866,14 +962,15 @@ export declare const fromEffectTake: (effect: Effect.Effect(queue: Queue.Dequeue) => Channel>; /** - * Create a channel from a queue that emits arrays of elements + * Creates a channel from a queue that emits arrays of elements. + * + * **Example** (Creating batched channels from queues) * - * @example * ```ts * import { Channel, Data, Effect, Queue } from "effect" * @@ -909,19 +1006,23 @@ export declare const fromQueue: (queue: Queue.Dequeue) => Channel(queue: Queue.Dequeue) => Channel, Exclude>; /** + * Creates a channel that forwards upstream input elements, input errors, and + * the upstream done value unchanged. + * + * @category constructors * @since 2.0.0 - * @category Constructors */ export declare const identity: () => Channel; /** - * Create a channel from a PubSub subscription + * Creates a channel from a PubSub subscription. + * + * **Example** (Creating channels from subscriptions) * - * @example * ```ts * import { Channel, Data, Effect, PubSub } from "effect" * @@ -958,21 +1059,21 @@ export declare const identity: () => Channel(subscription: PubSub.Subscription) => Channel; /** - * Create a channel from a PubSub subscription that outputs arrays of values. + * Creates a channel from a PubSub subscription that outputs arrays of values. + * + * **Details** * * This constructor creates a channel that reads from a PubSub subscription and outputs * arrays of values in chunks. It's useful when you want to process multiple values at once * for better performance. * - * @param subscription - The PubSub subscription to read from - * @param chunkSize - The maximum number of elements to read in each chunk (default: 4096) + * **Example** (Batching subscription values) * - * @example * ```ts * import { Channel, Data, Effect, PubSub } from "effect" * @@ -998,7 +1099,8 @@ export declare const fromSubscription: (subscription: PubSub.Subscription) * }) * ``` * - * @example + * **Example** (Processing subscription values in batches) + * * ```ts * import { Channel, Data, Effect, PubSub } from "effect" * @@ -1023,13 +1125,10 @@ export declare const fromSubscription: (subscription: PubSub.Subscription) * }) * ``` * - * @example - * ```ts - * import { Channel, Data, Effect, PubSub } from "effect" + * **Example** (Aggregating subscription metrics) * - * class MetricsError extends Data.TaggedError("MetricsError")<{ - * readonly cause: string - * }> {} + * ```ts + * import { Channel, Effect, PubSub } from "effect" * * const metricsAggregator = Effect.gen(function*() { * const metricsPubSub = yield* PubSub.bounded< @@ -1054,7 +1153,8 @@ export declare const fromSubscription: (subscription: PubSub.Subscription) * average: avg, * min, * max, - * timestamp: Date.now() + * firstTimestamp: Math.min(...metrics.map((m) => m.timestamp)), + * lastTimestamp: Math.max(...metrics.map((m) => m.timestamp)) * } * }) * @@ -1062,20 +1162,21 @@ export declare const fromSubscription: (subscription: PubSub.Subscription) * }) * ``` * - * @since 4.0.0 * @category constructors + * @since 4.0.0 */ export declare const fromSubscriptionArray: (subscription: PubSub.Subscription) => Channel>; /** - * Create a channel from a PubSub that outputs individual values. + * Creates a channel from a PubSub that outputs individual values. + * + * **Details** * * This constructor creates a channel that reads from a PubSub by automatically * subscribing to it. The channel outputs individual values as they are published * to the PubSub, making it ideal for real-time streaming scenarios. * - * @param pubsub - The PubSub to read from + * **Example** (Creating channels from PubSubs) * - * @example * ```ts * import { Channel, Data, Effect, PubSub } from "effect" * @@ -1099,13 +1200,10 @@ export declare const fromSubscriptionArray: (subscription: PubSub.Subscriptio * }) * ``` * - * @example - * ```ts - * import { Channel, Data, Effect, PubSub } from "effect" + * **Example** (Streaming PubSub notifications) * - * class NotificationError extends Data.TaggedError("NotificationError")<{ - * readonly reason: string - * }> {} + * ```ts + * import { Channel, Effect, PubSub } from "effect" * * const notificationService = Effect.gen(function*() { * const notificationPubSub = yield* PubSub.bounded(50) @@ -1114,24 +1212,21 @@ export declare const fromSubscriptionArray: (subscription: PubSub.Subscriptio * const notificationChannel = Channel.fromPubSub(notificationPubSub) * * // Transform notifications to add timestamps + * const receivedAt = "2024-01-01T00:00:00.000Z" * const timestampedChannel = Channel.map(notificationChannel, (message) => ({ * message, - * timestamp: new Date().toISOString(), - * id: Math.random().toString(36).substr(2, 9) + * receivedAt, + * id: `notification:${message}` * })) * * return timestampedChannel * }) * ``` * - * @example - * ```ts - * import { Channel, Data, Effect, PubSub } from "effect" + * **Example** (Processing PubSub events) * - * class EventProcessingError extends Data.TaggedError("EventProcessingError")<{ - * readonly eventType: string - * readonly cause: string - * }> {} + * ```ts + * import { Channel, Effect, PubSub } from "effect" * * interface DomainEvent { * readonly type: string @@ -1151,7 +1246,7 @@ export declare const fromSubscriptionArray: (subscription: PubSub.Subscriptio * return { * ...event, * processed: true, - * processedAt: Date.now() + * processedAt: event.timestamp + 1 * } * } * return event @@ -1161,21 +1256,21 @@ export declare const fromSubscriptionArray: (subscription: PubSub.Subscriptio * }) * ``` * - * @since 4.0.0 * @category constructors + * @since 2.0.0 */ export declare const fromPubSub: (pubsub: PubSub.PubSub) => Channel; /** - * Create a channel from a PubSub that outputs arrays of values. + * Creates a channel from a PubSub that outputs arrays of values. + * + * **Details** * * This constructor creates a channel that reads from a PubSub by automatically * subscribing to it and collecting values into arrays. The channel outputs * arrays of values in chunks, making it ideal for batch processing scenarios. * - * @param pubsub - The PubSub to read from - * @param chunkSize - The maximum number of elements to collect in each array (default: 4096) + * **Example** (Batching PubSub values) * - * @example * ```ts * import { Channel, Data, Effect, PubSub } from "effect" * @@ -1200,20 +1295,17 @@ export declare const fromPubSub: (pubsub: PubSub.PubSub) => Channel; * }) * ``` * - * @example - * ```ts - * import { Channel, Data, Effect, PubSub } from "effect" + * **Example** (Processing PubSub orders in batches) * - * class OrderProcessingError extends Data.TaggedError("OrderProcessingError")<{ - * readonly orderId: string - * readonly reason: string - * }> {} + * ```ts + * import { Channel, Effect, PubSub } from "effect" * * interface Order { * readonly id: string * readonly customerId: string * readonly items: ReadonlyArray * readonly total: number + * readonly submittedAt: number * } * * const orderBatchProcessor = Effect.gen(function*() { @@ -1233,7 +1325,7 @@ export declare const fromPubSub: (pubsub: PubSub.PubSub) => Channel; * batchSize: orderBatch.length, * totalRevenue, * uniqueCustomers: customerCount, - * processedAt: Date.now(), + * firstSubmittedAt: Math.min(...orderBatch.map((order) => order.submittedAt)), * orders: orderBatch * } * }) @@ -1242,14 +1334,10 @@ export declare const fromPubSub: (pubsub: PubSub.PubSub) => Channel; * }) * ``` * - * @example - * ```ts - * import { Channel, Data, Effect, PubSub } from "effect" + * **Example** (Processing PubSub logs in batches) * - * class LogProcessingError extends Data.TaggedError("LogProcessingError")<{ - * readonly batchId: string - * readonly cause: string - * }> {} + * ```ts + * import { Channel, Effect, PubSub } from "effect" * * interface LogEntry { * readonly timestamp: number @@ -1276,7 +1364,7 @@ export declare const fromPubSub: (pubsub: PubSub.PubSub) => Channel; * } * * return { - * batchId: Math.random().toString(36).substr(2, 9), + * batchId: `${timeRange.start}-${timeRange.end}`, * totalEntries: logBatch.length, * errorCount, * warnCount, @@ -1290,40 +1378,62 @@ export declare const fromPubSub: (pubsub: PubSub.PubSub) => Channel; * }) * ``` * - * @since 4.0.0 * @category constructors + * @since 4.0.0 */ export declare const fromPubSubArray: (pubsub: PubSub.PubSub) => Channel>; /** - * @since 4.0.0 + * Subscribes to a `PubSub` of `Take` values and exposes them as a channel. + * + * **Details** + * + * Output `Take` values are emitted as non-empty arrays. Failed `Take` values + * fail the channel. Done `Take` values complete the channel. + * * @category constructors + * @since 4.0.0 */ export declare const fromPubSubTake: (pubsub: PubSub.PubSub>) => Channel, E, Done>; /** * Creates a Channel from a Schedule. * - * @since 4.0.0 * @category constructors + * @since 4.0.0 */ export declare const fromSchedule: (schedule: Schedule.Schedule) => Channel; /** - * Creates a Channel from a AsyncIterable. + * Creates a channel that pulls values from an `AsyncIterable`. + * + * **Details** + * + * Each yielded value is emitted as an output element. The iterator's return + * value becomes the channel's done value. Thrown or rejected iterator errors + * are converted with `onError`. If the channel scope closes early and the + * iterator has a `return` method, that method is called. * - * @since 4.0.0 * @category constructors + * @since 4.0.0 */ export declare const fromAsyncIterable: (iterable: AsyncIterable, onError: (error: unknown) => E) => Channel; /** - * Creates a Channel from a AsyncIterable that emits arrays of elements. + * Creates a channel from an `AsyncIterable`, emitting each yielded value as a + * single-element non-empty array. + * + * **Details** + * + * The iterator's return value becomes the channel's done value. Thrown or + * rejected iterator errors are converted with `onError`. If the channel scope + * closes early and the iterator has a `return` method, that method is called. * - * @since 4.0.0 * @category constructors + * @since 4.0.0 */ export declare const fromAsyncIterableArray: (iterable: AsyncIterable, onError: (error: unknown) => E) => Channel, E, D>; /** * Maps the output of this channel using the specified function. * - * @example + * **Example** (Mapping channel output) + * * ```ts * import { Channel, Data } from "effect" * @@ -1355,14 +1465,15 @@ export declare const fromAsyncIterableArray: (iterable: AsyncIterable(f: (o: OutElem, i: number) => OutElem2): (self: Channel) => Channel; /** * Maps the output of this channel using the specified function. * - * @example + * **Example** (Mapping channel output) + * * ```ts * import { Channel, Data } from "effect" * @@ -1433,63 +1545,88 @@ export declare const map: { * })) * ``` * + * @category sequencing * @since 2.0.0 - * @category Sequencing */ (self: Channel, f: (o: OutElem, i: number) => OutElem2): Channel; }; /** * Maps the done value of this channel using the specified function. * - * @since 2.0.0 - * @category Sequencing + * @category sequencing + * @since 4.0.0 */ export declare const mapDone: { /** * Maps the done value of this channel using the specified function. * - * @since 2.0.0 - * @category Sequencing + * @category sequencing + * @since 4.0.0 */ (f: (o: OutDone) => OutDone2): (self: Channel) => Channel; /** * Maps the done value of this channel using the specified function. * - * @since 2.0.0 - * @category Sequencing + * @category sequencing + * @since 4.0.0 */ (self: Channel, f: (o: OutDone) => OutDone2): Channel; }; /** * Maps the done value of this channel using the specified effectful function. * - * @since 2.0.0 - * @category Sequencing + * **When to use** + * + * Use when the terminal done value transformation needs services or can fail, + * while emitted elements should pass through unchanged. + * + * @category sequencing + * @since 4.0.0 */ export declare const mapDoneEffect: { /** * Maps the done value of this channel using the specified effectful function. * - * @since 2.0.0 - * @category Sequencing + * **When to use** + * + * Use when the terminal done value transformation needs services or can fail, + * while emitted elements should pass through unchanged. + * + * @category sequencing + * @since 4.0.0 */ (f: (o: OutDone) => Effect.Effect): (self: Channel) => Channel; /** * Maps the done value of this channel using the specified effectful function. * - * @since 2.0.0 - * @category Sequencing + * **When to use** + * + * Use when the terminal done value transformation needs services or can fail, + * while emitted elements should pass through unchanged. + * + * @category sequencing + * @since 4.0.0 */ (self: Channel, f: (o: OutDone) => Effect.Effect): Channel; }; /** - * Returns a new channel, which sequentially combines this channel, together - * with the provided factory function, which creates a second channel based on - * the output values of this channel. The result is a channel that will first - * perform the functions of this channel, before performing the functions of - * the created channel (including yielding its terminal value). + * Maps each output element with an effectful function, preserving the source + * channel's done value. + * + * **When to use** + * + * Use when transforming each channel output needs an Effect, service + * dependency, failure channel, or configured concurrency. + * + * **Details** + * + * The mapping function receives the output element and its zero-based index. + * By default elements are mapped sequentially. Use `options.concurrency` to + * map multiple elements concurrently, and `options.unordered` to allow + * concurrently mapped outputs to be emitted as soon as they complete. + * + * **Example** (Mapping channel output with effects) * - * @example * ```ts * import { Channel, Data, Effect } from "effect" * @@ -1526,18 +1663,28 @@ export declare const mapDoneEffect: { * ) * ``` * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ export declare const mapEffect: { /** - * Returns a new channel, which sequentially combines this channel, together - * with the provided factory function, which creates a second channel based on - * the output values of this channel. The result is a channel that will first - * perform the functions of this channel, before performing the functions of - * the created channel (including yielding its terminal value). + * Maps each output element with an effectful function, preserving the source + * channel's done value. + * + * **When to use** + * + * Use when transforming each channel output needs an Effect, service + * dependency, failure channel, or configured concurrency. + * + * **Details** + * + * The mapping function receives the output element and its zero-based index. + * By default elements are mapped sequentially. Use `options.concurrency` to + * map multiple elements concurrently, and `options.unordered` to allow + * concurrently mapped outputs to be emitted as soon as they complete. + * + * **Example** (Mapping channel output with effects) * - * @example * ```ts * import { Channel, Data, Effect } from "effect" * @@ -1574,21 +1721,31 @@ export declare const mapEffect: { * ) * ``` * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ (f: (d: OutElem, i: number) => Effect.Effect, options?: { readonly concurrency?: number | "unbounded" | undefined; readonly unordered?: boolean | undefined; }): (self: Channel) => Channel; /** - * Returns a new channel, which sequentially combines this channel, together - * with the provided factory function, which creates a second channel based on - * the output values of this channel. The result is a channel that will first - * perform the functions of this channel, before performing the functions of - * the created channel (including yielding its terminal value). + * Maps each output element with an effectful function, preserving the source + * channel's done value. + * + * **When to use** + * + * Use when transforming each channel output needs an Effect, service + * dependency, failure channel, or configured concurrency. + * + * **Details** + * + * The mapping function receives the output element and its zero-based index. + * By default elements are mapped sequentially. Use `options.concurrency` to + * map multiple elements concurrently, and `options.unordered` to allow + * concurrently mapped outputs to be emitted as soon as they complete. + * + * **Example** (Mapping channel output with effects) * - * @example * ```ts * import { Channel, Data, Effect } from "effect" * @@ -1625,8 +1782,8 @@ export declare const mapEffect: { * ) * ``` * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ (self: Channel, f: (d: OutElem, i: number) => Effect.Effect, options?: { readonly concurrency?: number | "unbounded" | undefined; @@ -1637,24 +1794,24 @@ export declare const mapEffect: { * Returns a new channel which is the same as this one but applies the given * function to the input channel’s input elements. * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ export declare const mapInput: { /** * Returns a new channel which is the same as this one but applies the given * function to the input channel’s input elements. * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ (f: (i: InElem2) => Effect.Effect): (self: Channel) => Channel; /** * Returns a new channel which is the same as this one but applies the given * function to the input channel’s input elements. * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ (self: Channel, f: (i: InElem2) => Effect.Effect): Channel; }; @@ -1662,24 +1819,24 @@ export declare const mapInput: { * Returns a new channel which is the same as this one but applies the given * function to the input errors. * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ export declare const mapInputError: { /** * Returns a new channel which is the same as this one but applies the given * function to the input errors. * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ (f: (i: InErr2) => Effect.Effect): (self: Channel) => Channel; /** * Returns a new channel which is the same as this one but applies the given * function to the input errors. * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ (self: Channel, f: (i: InErr2) => Effect.Effect): Channel; }; @@ -1687,11 +1844,14 @@ export declare const mapInputError: { * Applies a side effect function to each output element of the channel, * returning a new channel that emits the same elements. * + * **Details** + * * The `tap` function allows you to perform side effects (like logging or * debugging) on each element emitted by a channel without modifying the * elements themselves. * - * @example + * **Example** (Tapping channel output) + * * ```ts * import { Channel, Console, Data } from "effect" * @@ -1712,19 +1872,22 @@ export declare const mapInputError: { * // Outputs: 1, 2, 3 (while logging each) * ``` * - * @since 4.0.0 * @category sequencing + * @since 4.0.0 */ export declare const tap: { /** * Applies a side effect function to each output element of the channel, * returning a new channel that emits the same elements. * + * **Details** + * * The `tap` function allows you to perform side effects (like logging or * debugging) on each element emitted by a channel without modifying the * elements themselves. * - * @example + * **Example** (Tapping channel output) + * * ```ts * import { Channel, Console, Data } from "effect" * @@ -1745,8 +1908,8 @@ export declare const tap: { * // Outputs: 1, 2, 3 (while logging each) * ``` * - * @since 4.0.0 * @category sequencing + * @since 4.0.0 */ (f: (d: Types.NoInfer) => Effect.Effect, options?: { readonly concurrency?: number | "unbounded" | undefined; @@ -1755,11 +1918,14 @@ export declare const tap: { * Applies a side effect function to each output element of the channel, * returning a new channel that emits the same elements. * + * **Details** + * * The `tap` function allows you to perform side effects (like logging or * debugging) on each element emitted by a channel without modifying the * elements themselves. * - * @example + * **Example** (Tapping channel output) + * * ```ts * import { Channel, Console, Data } from "effect" * @@ -1780,21 +1946,26 @@ export declare const tap: { * // Outputs: 1, 2, 3 (while logging each) * ``` * - * @since 4.0.0 * @category sequencing + * @since 4.0.0 */ (self: Channel, f: (d: Types.NoInfer) => Effect.Effect, options?: { readonly concurrency?: number | "unbounded" | undefined; }): Channel; }; /** - * Returns a new channel, which sequentially combines this channel, together - * with the provided factory function, which creates a second channel based on - * the output values of this channel. The result is a channel that will first - * perform the functions of this channel, before performing the functions of - * the created channel (including yielding its terminal value). + * Maps each output element to a channel and flattens the child channel + * outputs. + * + * **Details** + * + * The source channel's done value is preserved. Child channel done values are + * used only for child-channel completion. By default child channels are run + * sequentially. Use `options.concurrency` and `options.bufferSize` to run child + * channels concurrently. + * + * **Example** (FlatMapping channel output) * - * @example * ```ts * import { Channel, Data } from "effect" * @@ -1816,18 +1987,23 @@ export declare const tap: { * // Outputs: "item-1-0", "item-2-0", "item-2-1", "item-3-0", "item-3-1", "item-3-2" * ``` * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ export declare const flatMap: { /** - * Returns a new channel, which sequentially combines this channel, together - * with the provided factory function, which creates a second channel based on - * the output values of this channel. The result is a channel that will first - * perform the functions of this channel, before performing the functions of - * the created channel (including yielding its terminal value). + * Maps each output element to a channel and flattens the child channel + * outputs. + * + * **Details** + * + * The source channel's done value is preserved. Child channel done values are + * used only for child-channel completion. By default child channels are run + * sequentially. Use `options.concurrency` and `options.bufferSize` to run child + * channels concurrently. + * + * **Example** (FlatMapping channel output) * - * @example * ```ts * import { Channel, Data } from "effect" * @@ -1849,21 +2025,26 @@ export declare const flatMap: { * // Outputs: "item-1-0", "item-2-0", "item-2-1", "item-3-0", "item-3-1", "item-3-2" * ``` * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ (f: (d: OutElem) => Channel, options?: { readonly concurrency?: number | "unbounded" | undefined; readonly bufferSize?: number | undefined; }): (self: Channel) => Channel; /** - * Returns a new channel, which sequentially combines this channel, together - * with the provided factory function, which creates a second channel based on - * the output values of this channel. The result is a channel that will first - * perform the functions of this channel, before performing the functions of - * the created channel (including yielding its terminal value). + * Maps each output element to a channel and flattens the child channel + * outputs. + * + * **Details** + * + * The source channel's done value is preserved. Child channel done values are + * used only for child-channel completion. By default child channels are run + * sequentially. Use `options.concurrency` and `options.bufferSize` to run child + * channels concurrently. + * + * **Example** (FlatMapping channel output) * - * @example * ```ts * import { Channel, Data } from "effect" * @@ -1885,8 +2066,8 @@ export declare const flatMap: { * // Outputs: "item-1-0", "item-2-0", "item-2-1", "item-3-0", "item-3-1", "item-3-2" * ``` * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ (self: Channel, f: (d: OutElem) => Channel, options?: { readonly concurrency?: number | "unbounded" | undefined; @@ -1897,7 +2078,8 @@ export declare const flatMap: { * Concatenates this channel with another channel created from the terminal value * of this channel. The new channel is created using the provided function. * - * @example + * **Example** (Concatenating with completion values) + * * ```ts * import { Channel, Data } from "effect" * @@ -1914,15 +2096,16 @@ export declare const flatMap: { * // Outputs: 1, 2, 3, then "Completed processing" * ``` * - * @since 2.0.0 * @category sequencing + * @since 4.0.0 */ export declare const concatWith: { /** * Concatenates this channel with another channel created from the terminal value * of this channel. The new channel is created using the provided function. * - * @example + * **Example** (Concatenating with completion values) + * * ```ts * import { Channel, Data } from "effect" * @@ -1939,15 +2122,16 @@ export declare const concatWith: { * // Outputs: 1, 2, 3, then "Completed processing" * ``` * - * @since 2.0.0 * @category sequencing + * @since 4.0.0 */ (f: (leftover: Types.NoInfer) => Channel): (self: Channel) => Channel; /** * Concatenates this channel with another channel created from the terminal value * of this channel. The new channel is created using the provided function. * - * @example + * **Example** (Concatenating with completion values) + * * ```ts * import { Channel, Data } from "effect" * @@ -1964,8 +2148,8 @@ export declare const concatWith: { * // Outputs: 1, 2, 3, then "Completed processing" * ``` * - * @since 2.0.0 * @category sequencing + * @since 4.0.0 */ (self: Channel, f: (leftover: Types.NoInfer) => Channel): Channel; }; @@ -1973,7 +2157,8 @@ export declare const concatWith: { * Concatenates this channel with another channel, so that the second channel * starts emitting values after the first channel has completed. * - * @example + * **Example** (Concatenating channels) + * * ```ts * import { Channel, Data } from "effect" * @@ -1991,15 +2176,16 @@ export declare const concatWith: { * // Outputs: 1, 2, 3, "a", "b", "c" * ``` * - * @since 2.0.0 * @category sequencing + * @since 4.0.0 */ export declare const concat: { /** * Concatenates this channel with another channel, so that the second channel * starts emitting values after the first channel has completed. * - * @example + * **Example** (Concatenating channels) + * * ```ts * import { Channel, Data } from "effect" * @@ -2017,15 +2203,16 @@ export declare const concat: { * // Outputs: 1, 2, 3, "a", "b", "c" * ``` * - * @since 2.0.0 * @category sequencing + * @since 4.0.0 */ (that: Channel): (self: Channel) => Channel; /** * Concatenates this channel with another channel, so that the second channel * starts emitting values after the first channel has completed. * - * @example + * **Example** (Concatenating channels) + * * ```ts * import { Channel, Data } from "effect" * @@ -2043,65 +2230,114 @@ export declare const concat: { * // Outputs: 1, 2, 3, "a", "b", "c" * ``` * - * @since 2.0.0 * @category sequencing + * @since 4.0.0 */ (self: Channel, that: Channel): Channel; }; /** - * Combines the elements from this channel and the specified channel by - * repeatedly applying the function `f` to extract an element using both sides - * and conceptually "offer" it to the destination channel. `f` can maintain - * some internal state to control the combining process, with the initial - * state being specified by `s`. + * Combines two channels with a stateful pull function. + * + * **When to use** + * + * Use to coordinate pulling from two channels when each output element depends + * on both sides and local state. + * + * **Details** + * + * The combining function receives the current state and pull functions for the + * left and right channels. It returns the next output element together with the + * next state. * - * @since 4.0.0 * @category sequencing + * @since 4.0.0 */ export declare const combine: { /** - * Combines the elements from this channel and the specified channel by - * repeatedly applying the function `f` to extract an element using both sides - * and conceptually "offer" it to the destination channel. `f` can maintain - * some internal state to control the combining process, with the initial - * state being specified by `s`. + * Combines two channels with a stateful pull function. + * + * **When to use** + * + * Use to coordinate pulling from two channels when each output element depends + * on both sides and local state. + * + * **Details** + * + * The combining function receives the current state and pull functions for the + * left and right channels. It returns the next output element together with the + * next state. * - * @since 4.0.0 * @category sequencing + * @since 4.0.0 */ (that: Channel, s: LazyArg, f: (s: S, pullLeft: Pull.Pull, pullRight: Pull.Pull) => Effect.Effect): (self: Channel) => Channel, Cause.Done.Extract, InElem & InElem2, InErr & InErr2, InDone & InDone2, Env | Env2 | R>; /** - * Combines the elements from this channel and the specified channel by - * repeatedly applying the function `f` to extract an element using both sides - * and conceptually "offer" it to the destination channel. `f` can maintain - * some internal state to control the combining process, with the initial - * state being specified by `s`. + * Combines two channels with a stateful pull function. + * + * **When to use** + * + * Use to coordinate pulling from two channels when each output element depends + * on both sides and local state. + * + * **Details** + * + * The combining function receives the current state and pull functions for the + * left and right channels. It returns the next output element together with the + * next state. * - * @since 4.0.0 * @category sequencing + * @since 4.0.0 */ (self: Channel, that: Channel, s: LazyArg, f: (s: S, pullLeft: Pull.Pull, pullRight: Pull.Pull) => Effect.Effect): Channel, Cause.Done.Extract, InElem & InElem2, InErr & InErr2, InDone & InDone2, Env | Env2 | R>; }; /** - * @since 2.0.0 + * Runs a fallback channel if this channel completes without emitting any + * output elements. + * + * **Details** + * + * If the source emits at least one element, the source is used unchanged. If + * the source completes before emitting an element, the fallback function + * receives the source done value and returns the replacement channel. + * * @category sequencing + * @since 4.0.0 */ export declare const orElseIfEmpty: { /** - * @since 2.0.0 + * Runs a fallback channel if this channel completes without emitting any + * output elements. + * + * **Details** + * + * If the source emits at least one element, the source is used unchanged. If + * the source completes before emitting an element, the fallback function + * receives the source done value and returns the replacement channel. + * * @category sequencing + * @since 4.0.0 */ (f: (leftover: Types.NoInfer) => Channel): (self: Channel) => Channel; /** - * @since 2.0.0 + * Runs a fallback channel if this channel completes without emitting any + * output elements. + * + * **Details** + * + * If the source emits at least one element, the source is used unchanged. If + * the source completes before emitting an element, the fallback function + * receives the source done value and returns the replacement channel. + * * @category sequencing + * @since 4.0.0 */ (self: Channel, f: (leftover: Types.NoInfer) => Channel): Channel; }; /** - * Flatten a channel of channels. + * Flattens a channel of channels. + * + * **Example** (Flattening nested channels) * - * @example * ```ts * import { Channel, Data } from "effect" * @@ -2122,14 +2358,15 @@ export declare const orElseIfEmpty: { * // Outputs: 1, 2, 3, 4, 5, 6 * ``` * - * @since 2.0.0 * @category constructors + * @since 2.0.0 */ export declare const flatten: (channels: Channel, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1>) => Channel; /** * Flattens a channel that outputs arrays into a channel that outputs individual elements. * - * @example + * **Example** (Flattening arrays of channel output) + * * ```ts * import { Channel, Data } from "effect" * @@ -2150,20 +2387,29 @@ export declare const flatten: (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>) => Channel; /** + * Flattens a channel that emits `Take` values into a channel that emits the + * `Take` outputs directly. + * + * **Details** + * + * Output `Take` values are emitted as non-empty arrays. Failed `Take` values + * fail the returned channel. Done `Take` values complete the returned channel. + * + * @category transforming * @since 4.0.0 - * @category utils */ export declare const flattenTake: (self: Channel, OutErr2, OutDone2, InElem, InErr, InDone, Env>) => Channel, OutErr | OutErr2, OutDone, InElem, InErr, InDone, Env>; /** * Creates a new channel that consumes all output from the source channel * but emits nothing, preserving only the completion value. * - * @example + * **Example** (Draining channel output) + * * ```ts * import { Channel } from "effect" * @@ -2177,52 +2423,82 @@ export declare const flattenTake: (self: Channel) => Channel; /** * Repeats this channel according to the provided schedule. * + * @category repetition * @since 4.0.0 - * @category utils */ export declare const repeat: { /** * Repeats this channel according to the provided schedule. * + * @category repetition * @since 4.0.0 - * @category utils */ (schedule: Schedule.Schedule, SE, SR> | (($: (_: Schedule.Schedule, SE, SR>) => Schedule.Schedule) => Schedule.Schedule, SE, SR>)): (self: Channel) => Channel; /** * Repeats this channel according to the provided schedule. * + * @category repetition * @since 4.0.0 - * @category utils */ (self: Channel, schedule: Schedule.Schedule | (($: (_: Schedule.Schedule, SE, SR>) => Schedule.Schedule) => Schedule.Schedule, SE, SR>)): Channel; }; /** * Repeats this channel forever. * + * @category repetition * @since 4.0.0 - * @category utils */ export declare const forever: (self: Channel) => Channel; /** + * Runs a schedule step for each output element while preserving the emitted + * elements. + * + * **Details** + * + * The schedule receives each output element as input. Schedule delays are + * applied between emitted elements. If the schedule fails, the returned channel + * fails. If the schedule finishes, the returned channel completes with the + * schedule output. + * + * @category sequencing * @since 4.0.0 - * @category utils */ export declare const schedule: { /** + * Runs a schedule step for each output element while preserving the emitted + * elements. + * + * **Details** + * + * The schedule receives each output element as input. Schedule delays are + * applied between emitted elements. If the schedule fails, the returned channel + * fails. If the schedule finishes, the returned channel completes with the + * schedule output. + * + * @category sequencing * @since 4.0.0 - * @category utils */ (schedule: Schedule.Schedule, SE, SR>): (self: Channel) => Channel; /** + * Runs a schedule step for each output element while preserving the emitted + * elements. + * + * **Details** + * + * The schedule receives each output element as input. Schedule delays are + * applied between emitted elements. If the schedule fails, the returned channel + * fails. If the schedule finishes, the returned channel completes with the + * schedule output. + * + * @category sequencing * @since 4.0.0 - * @category utils */ (self: Channel, schedule: Schedule.Schedule): Channel; }; @@ -2230,7 +2506,8 @@ export declare const schedule: { * Filters the output elements of a channel using a predicate function. * Elements that don't match the predicate are discarded. * - * @example + * **Example** (Filtering channel output) + * * ```ts * import { Channel } from "effect" * @@ -2250,15 +2527,16 @@ export declare const schedule: { * // Outputs: 1, 2, 3 (all typed as numbers) * ``` * - * @since 2.0.0 - * @category Filtering + * @category filtering + * @since 4.0.0 */ export declare const filter: { /** * Filters the output elements of a channel using a predicate function. * Elements that don't match the predicate are discarded. * - * @example + * **Example** (Filtering channel output) + * * ```ts * import { Channel } from "effect" * @@ -2278,15 +2556,16 @@ export declare const filter: { * // Outputs: 1, 2, 3 (all typed as numbers) * ``` * - * @since 2.0.0 - * @category Filtering + * @category filtering + * @since 4.0.0 */ (refinement: Predicate.Refinement): (self: Channel) => Channel; /** * Filters the output elements of a channel using a predicate function. * Elements that don't match the predicate are discarded. * - * @example + * **Example** (Filtering channel output) + * * ```ts * import { Channel } from "effect" * @@ -2306,15 +2585,16 @@ export declare const filter: { * // Outputs: 1, 2, 3 (all typed as numbers) * ``` * - * @since 2.0.0 - * @category Filtering + * @category filtering + * @since 4.0.0 */ (predicate: Predicate.Predicate): (self: Channel) => Channel; /** * Filters the output elements of a channel using a predicate function. * Elements that don't match the predicate are discarded. * - * @example + * **Example** (Filtering channel output) + * * ```ts * import { Channel } from "effect" * @@ -2334,15 +2614,16 @@ export declare const filter: { * // Outputs: 1, 2, 3 (all typed as numbers) * ``` * - * @since 2.0.0 - * @category Filtering + * @category filtering + * @since 4.0.0 */ (self: Channel, refinement: Predicate.Refinement): Channel; /** * Filters the output elements of a channel using a predicate function. * Elements that don't match the predicate are discarded. * - * @example + * **Example** (Filtering channel output) + * * ```ts * import { Channel } from "effect" * @@ -2362,56 +2643,200 @@ export declare const filter: { * // Outputs: 1, 2, 3 (all typed as numbers) * ``` * - * @since 2.0.0 - * @category Filtering + * @category filtering + * @since 4.0.0 */ (self: Channel, predicate: Predicate.Predicate): Channel; }; /** + * Filters and maps output elements using a `Filter`. + * + * **When to use** + * + * Use to keep only channel output elements accepted by a `Filter` and emit + * each filter success value. + * + * **Details** + * + * Successful filter results are emitted as mapped values. Failed filter + * results are discarded. The source channel's errors and done value are + * preserved. + * + * @see {@link filter} for keeping original output elements with a predicate + * @see {@link filterMapEffect} for using an effectful `Filter` + * @see {@link filterMapArray} for filtering arrays of output elements + * + * @category filtering * @since 4.0.0 - * @category Filtering */ export declare const filterMap: { /** + * Filters and maps output elements using a `Filter`. + * + * **When to use** + * + * Use to keep only channel output elements accepted by a `Filter` and emit + * each filter success value. + * + * **Details** + * + * Successful filter results are emitted as mapped values. Failed filter + * results are discarded. The source channel's errors and done value are + * preserved. + * + * @see {@link filter} for keeping original output elements with a predicate + * @see {@link filterMapEffect} for using an effectful `Filter` + * @see {@link filterMapArray} for filtering arrays of output elements + * + * @category filtering * @since 4.0.0 - * @category Filtering */ (filter: Filter.Filter): (self: Channel) => Channel; /** + * Filters and maps output elements using a `Filter`. + * + * **When to use** + * + * Use to keep only channel output elements accepted by a `Filter` and emit + * each filter success value. + * + * **Details** + * + * Successful filter results are emitted as mapped values. Failed filter + * results are discarded. The source channel's errors and done value are + * preserved. + * + * @see {@link filter} for keeping original output elements with a predicate + * @see {@link filterMapEffect} for using an effectful `Filter` + * @see {@link filterMapArray} for filtering arrays of output elements + * + * @category filtering * @since 4.0.0 - * @category Filtering */ (self: Channel, filter: Filter.Filter): Channel; }; /** + * Filters output elements with an effectful predicate. + * + * **When to use** + * + * Use when the keep/discard decision depends on an Effect or service and + * predicate failures should fail the returned channel. + * + * **Details** + * + * Elements for which the predicate succeeds with `true` are emitted. Elements + * for which the predicate succeeds with `false` are discarded. Predicate + * failures fail the returned channel. + * + * @category filtering * @since 4.0.0 - * @category Filtering */ export declare const filterEffect: { /** + * Filters output elements with an effectful predicate. + * + * **When to use** + * + * Use when the keep/discard decision depends on an Effect or service and + * predicate failures should fail the returned channel. + * + * **Details** + * + * Elements for which the predicate succeeds with `true` are emitted. Elements + * for which the predicate succeeds with `false` are discarded. Predicate + * failures fail the returned channel. + * + * @category filtering * @since 4.0.0 - * @category Filtering */ (predicate: (a: OutElem) => Effect.Effect): (self: Channel) => Channel; /** + * Filters output elements with an effectful predicate. + * + * **When to use** + * + * Use when the keep/discard decision depends on an Effect or service and + * predicate failures should fail the returned channel. + * + * **Details** + * + * Elements for which the predicate succeeds with `true` are emitted. Elements + * for which the predicate succeeds with `false` are discarded. Predicate + * failures fail the returned channel. + * + * @category filtering * @since 4.0.0 - * @category Filtering */ (self: Channel, predicate: (a: OutElem) => Effect.Effect): Channel; }; /** + * Filters and maps output elements using an effectful `Filter`. + * + * **When to use** + * + * Use to apply effectful logic that can discard channel output elements and + * emit transformed values for the elements that pass. + * + * **Details** + * + * Successful filter results are emitted as mapped values. Failed filter + * results are discarded. Failures from the effectful filter fail the returned + * channel. + * + * @see {@link filterMap} for using a synchronous `Filter` + * @see {@link filterEffect} for effectfully keeping original output elements + * @see {@link mapEffect} for effectfully transforming every output element + * @see {@link filterMapArrayEffect} for effectful filtering of array outputs + * + * @category filtering * @since 4.0.0 - * @category Filtering */ export declare const filterMapEffect: { /** + * Filters and maps output elements using an effectful `Filter`. + * + * **When to use** + * + * Use to apply effectful logic that can discard channel output elements and + * emit transformed values for the elements that pass. + * + * **Details** + * + * Successful filter results are emitted as mapped values. Failed filter + * results are discarded. Failures from the effectful filter fail the returned + * channel. + * + * @see {@link filterMap} for using a synchronous `Filter` + * @see {@link filterEffect} for effectfully keeping original output elements + * @see {@link mapEffect} for effectfully transforming every output element + * @see {@link filterMapArrayEffect} for effectful filtering of array outputs + * + * @category filtering * @since 4.0.0 - * @category Filtering */ (filter: Filter.FilterEffect): (self: Channel) => Channel; /** + * Filters and maps output elements using an effectful `Filter`. + * + * **When to use** + * + * Use to apply effectful logic that can discard channel output elements and + * emit transformed values for the elements that pass. + * + * **Details** + * + * Successful filter results are emitted as mapped values. Failed filter + * results are discarded. Failures from the effectful filter fail the returned + * channel. + * + * @see {@link filterMap} for using a synchronous `Filter` + * @see {@link filterEffect} for effectfully keeping original output elements + * @see {@link mapEffect} for effectfully transforming every output element + * @see {@link filterMapArrayEffect} for effectful filtering of array outputs + * + * @category filtering * @since 4.0.0 - * @category Filtering */ (self: Channel, filter: Filter.FilterEffect): Channel; }; @@ -2419,7 +2844,8 @@ export declare const filterMapEffect: { * Filters arrays of elements emitted by a channel, applying the filter * to each element within the arrays and only emitting non-empty filtered arrays. * - * @example + * **Example** (Filtering array output) + * * ```ts * import { Array, Channel } from "effect" * @@ -2447,15 +2873,16 @@ export declare const filterMapEffect: { * // Outputs: [2, 4] (the arrays [1,3,5] and [7,9] are discarded) * ``` * + * @category filtering * @since 4.0.0 - * @category Filtering */ export declare const filterArray: { /** * Filters arrays of elements emitted by a channel, applying the filter * to each element within the arrays and only emitting non-empty filtered arrays. * - * @example + * **Example** (Filtering array output) + * * ```ts * import { Array, Channel } from "effect" * @@ -2483,15 +2910,16 @@ export declare const filterArray: { * // Outputs: [2, 4] (the arrays [1,3,5] and [7,9] are discarded) * ``` * + * @category filtering * @since 4.0.0 - * @category Filtering */ (refinement: Predicate.Refinement): (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>) => Channel, OutErr, OutDone, InElem, InErr, InDone, Env>; /** * Filters arrays of elements emitted by a channel, applying the filter * to each element within the arrays and only emitting non-empty filtered arrays. * - * @example + * **Example** (Filtering array output) + * * ```ts * import { Array, Channel } from "effect" * @@ -2519,15 +2947,16 @@ export declare const filterArray: { * // Outputs: [2, 4] (the arrays [1,3,5] and [7,9] are discarded) * ``` * + * @category filtering * @since 4.0.0 - * @category Filtering */ (predicate: Predicate.Predicate>): (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>) => Channel, OutErr, OutDone, InElem, InErr, InDone, Env>; /** * Filters arrays of elements emitted by a channel, applying the filter * to each element within the arrays and only emitting non-empty filtered arrays. * - * @example + * **Example** (Filtering array output) + * * ```ts * import { Array, Channel } from "effect" * @@ -2555,15 +2984,16 @@ export declare const filterArray: { * // Outputs: [2, 4] (the arrays [1,3,5] and [7,9] are discarded) * ``` * + * @category filtering * @since 4.0.0 - * @category Filtering */ (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>, refinement: Predicate.Refinement): Channel, OutErr, OutDone, InElem, InErr, InDone, Env>; /** * Filters arrays of elements emitted by a channel, applying the filter * to each element within the arrays and only emitting non-empty filtered arrays. * - * @example + * **Example** (Filtering array output) + * * ```ts * import { Array, Channel } from "effect" * @@ -2591,63 +3021,172 @@ export declare const filterArray: { * // Outputs: [2, 4] (the arrays [1,3,5] and [7,9] are discarded) * ``` * + * @category filtering * @since 4.0.0 - * @category Filtering */ (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>, predicate: Predicate.Predicate>): Channel, OutErr, OutDone, InElem, InErr, InDone, Env>; }; /** + * Filters and maps each element inside emitted non-empty arrays using a + * `Filter`. + * + * **Details** + * + * Successful filter results are kept as mapped values. Failed filter results + * are removed from the array. Arrays that become empty are discarded. + * + * @category filtering * @since 4.0.0 - * @category Filtering */ export declare const filterMapArray: { /** + * Filters and maps each element inside emitted non-empty arrays using a + * `Filter`. + * + * **Details** + * + * Successful filter results are kept as mapped values. Failed filter results + * are removed from the array. Arrays that become empty are discarded. + * + * @category filtering * @since 4.0.0 - * @category Filtering */ (filter: Filter.Filter, B, X>): (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>) => Channel, OutErr, OutDone, InElem, InErr, InDone, Env>; /** + * Filters and maps each element inside emitted non-empty arrays using a + * `Filter`. + * + * **Details** + * + * Successful filter results are kept as mapped values. Failed filter results + * are removed from the array. Arrays that become empty are discarded. + * + * @category filtering * @since 4.0.0 - * @category Filtering */ (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>, filter: Filter.Filter): Channel, OutErr, OutDone, InElem, InErr, InDone, Env>; }; /** + * Filters each element inside emitted non-empty arrays with an effectful + * predicate. + * + * **When to use** + * + * Use when filtering array-valued channel outputs requires Effects or services, + * and arrays that become empty should be skipped. + * + * **Details** + * + * The predicate receives the element and its index within the array. Elements + * for which the predicate succeeds with `true` are kept. Arrays that become + * empty are discarded. Predicate failures fail the returned channel. + * + * @category filtering * @since 4.0.0 - * @category Filtering */ export declare const filterArrayEffect: { /** + * Filters each element inside emitted non-empty arrays with an effectful + * predicate. + * + * **When to use** + * + * Use when filtering array-valued channel outputs requires Effects or services, + * and arrays that become empty should be skipped. + * + * **Details** + * + * The predicate receives the element and its index within the array. Elements + * for which the predicate succeeds with `true` are kept. Arrays that become + * empty are discarded. Predicate failures fail the returned channel. + * + * @category filtering * @since 4.0.0 - * @category Filtering */ (predicate: (a: Types.NoInfer, index: number) => Effect.Effect): (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>) => Channel, OutErr | E, OutDone, InElem, InErr, InDone, Env | R>; /** + * Filters each element inside emitted non-empty arrays with an effectful + * predicate. + * + * **When to use** + * + * Use when filtering array-valued channel outputs requires Effects or services, + * and arrays that become empty should be skipped. + * + * **Details** + * + * The predicate receives the element and its index within the array. Elements + * for which the predicate succeeds with `true` are kept. Arrays that become + * empty are discarded. Predicate failures fail the returned channel. + * + * @category filtering * @since 4.0.0 - * @category Filtering */ (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>, predicate: (a: Types.NoInfer, index: number) => Effect.Effect): Channel, OutErr | E, OutDone, InElem, InErr, InDone, Env | R>; }; /** + * Filters and maps each element inside emitted non-empty arrays using an + * effectful `Filter`. + * + * **When to use** + * + * Use when array-valued channel outputs need an effectful filter-map that can + * fail and can discard arrays that become empty. + * + * **Details** + * + * Successful filter results are kept as mapped values. Failed filter results + * are removed from the array. Arrays that become empty are discarded. Failures + * from the effectful filter fail the returned channel. + * + * @category filtering * @since 4.0.0 - * @category Filtering */ export declare const filterMapArrayEffect: { /** + * Filters and maps each element inside emitted non-empty arrays using an + * effectful `Filter`. + * + * **When to use** + * + * Use when array-valued channel outputs need an effectful filter-map that can + * fail and can discard arrays that become empty. + * + * **Details** + * + * Successful filter results are kept as mapped values. Failed filter results + * are removed from the array. Arrays that become empty are discarded. Failures + * from the effectful filter fail the returned channel. + * + * @category filtering * @since 4.0.0 - * @category Filtering */ (filter: Filter.FilterEffect, B, X, EX, RX>): (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>) => Channel, OutErr | EX, OutDone, InElem, InErr, InDone, Env | RX>; /** + * Filters and maps each element inside emitted non-empty arrays using an + * effectful `Filter`. + * + * **When to use** + * + * Use when array-valued channel outputs need an effectful filter-map that can + * fail and can discard arrays that become empty. + * + * **Details** + * + * Successful filter results are kept as mapped values. Failed filter results + * are removed from the array. Arrays that become empty are discarded. Failures + * from the effectful filter fail the returned channel. + * + * @category filtering * @since 4.0.0 - * @category Filtering */ (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>, filter: Filter.FilterEffect): Channel, OutErr | EX, OutDone, InElem, InErr, InDone, Env | RX>; }; /** - * Statefully maps over a channel with an accumulator, where each element can produce multiple output values. + * Maps over a channel statefully with an accumulator, where each element can produce multiple output values. + * + * **Example** (Mapping with accumulated state) * - * @example * ```ts * import { Channel, Effect } from "effect" * @@ -2678,14 +3217,15 @@ export declare const filterMapArrayEffect: { * ) * ``` * - * @since 2.0.0 - * @category Sequencing + * @category sequencing + * @since 4.0.0 */ export declare const mapAccum: { /** - * Statefully maps over a channel with an accumulator, where each element can produce multiple output values. + * Maps over a channel statefully with an accumulator, where each element can produce multiple output values. + * + * **Example** (Mapping with accumulated state) * - * @example * ```ts * import { Channel, Effect } from "effect" * @@ -2716,16 +3256,17 @@ export declare const mapAccum: { * ) * ``` * - * @since 2.0.0 - * @category Sequencing + * @category sequencing + * @since 4.0.0 */ (initial: LazyArg, f: (s: S, a: Types.NoInfer) => Effect.Effect], E, R> | readonly [state: S, values: ReadonlyArray], options?: { readonly onHalt?: ((state: S) => Array) | undefined; }): (self: Channel) => Channel; /** - * Statefully maps over a channel with an accumulator, where each element can produce multiple output values. + * Maps over a channel statefully with an accumulator, where each element can produce multiple output values. + * + * **Example** (Mapping with accumulated state) * - * @example * ```ts * import { Channel, Effect } from "effect" * @@ -2756,18 +3297,19 @@ export declare const mapAccum: { * ) * ``` * - * @since 2.0.0 - * @category Sequencing + * @category sequencing + * @since 4.0.0 */ (self: Channel, initial: LazyArg, f: (s: S, a: Types.NoInfer) => Effect.Effect], E, R> | readonly [state: S, values: ReadonlyArray], options?: { readonly onHalt?: ((state: S) => Array) | undefined; }): Channel; }; /** - * Statefully transforms a channel by scanning over its output with an accumulator function. + * Transforms a channel statefully by scanning over its output with an accumulator function. * Emits the intermediate results of the scan operation. * - * @example + * **Example** (Scanning channel output) + * * ```ts * import { Channel } from "effect" * @@ -2789,15 +3331,16 @@ export declare const mapAccum: { * // Outputs: "", "hello", "hello world", "hello world from", "hello world from effect" * ``` * - * @since 2.0.0 - * @category Sequencing + * @category sequencing + * @since 4.0.0 */ export declare const scan: { /** - * Statefully transforms a channel by scanning over its output with an accumulator function. + * Transforms a channel statefully by scanning over its output with an accumulator function. * Emits the intermediate results of the scan operation. * - * @example + * **Example** (Scanning channel output) + * * ```ts * import { Channel } from "effect" * @@ -2819,15 +3362,16 @@ export declare const scan: { * // Outputs: "", "hello", "hello world", "hello world from", "hello world from effect" * ``` * - * @since 2.0.0 - * @category Sequencing + * @category sequencing + * @since 4.0.0 */ (initial: S, f: (s: S, a: Types.NoInfer) => S): (self: Channel) => Channel; /** - * Statefully transforms a channel by scanning over its output with an accumulator function. + * Transforms a channel statefully by scanning over its output with an accumulator function. * Emits the intermediate results of the scan operation. * - * @example + * **Example** (Scanning channel output) + * * ```ts * import { Channel } from "effect" * @@ -2849,16 +3393,22 @@ export declare const scan: { * // Outputs: "", "hello", "hello world", "hello world from", "hello world from effect" * ``` * - * @since 2.0.0 - * @category Sequencing + * @category sequencing + * @since 4.0.0 */ (self: Channel, initial: S, f: (s: S, a: Types.NoInfer) => S): Channel; }; /** - * Statefully transforms a channel by scanning over its output with an effectful accumulator function. + * Transforms a channel statefully by scanning over its output with an effectful accumulator function. * Emits the intermediate results of the scan operation. * - * @example + * **When to use** + * + * Use when maintaining accumulated state over channel output requires Effects + * or can fail, while still emitting each intermediate state. + * + * **Example** (Scanning channel output with effects) + * * ```ts * import { Channel, Data, Effect } from "effect" * @@ -2895,16 +3445,22 @@ export declare const scan: { * ) * ``` * - * @since 2.0.0 - * @category Sequencing + * @category sequencing + * @since 4.0.0 */ export declare const scanEffect: { /** - * Statefully transforms a channel by scanning over its output with an effectful accumulator function. + * Transforms a channel statefully by scanning over its output with an effectful accumulator function. * Emits the intermediate results of the scan operation. * - * @example - * ```ts + * **When to use** + * + * Use when maintaining accumulated state over channel output requires Effects + * or can fail, while still emitting each intermediate state. + * + * **Example** (Scanning channel output with effects) + * + * ```ts * import { Channel, Data, Effect } from "effect" * * class ScanError extends Data.TaggedError("ScanError")<{ @@ -2940,15 +3496,21 @@ export declare const scanEffect: { * ) * ``` * - * @since 2.0.0 - * @category Sequencing + * @category sequencing + * @since 4.0.0 */ (initial: S, f: (s: S, a: Types.NoInfer) => Effect.Effect): (self: Channel) => Channel; /** - * Statefully transforms a channel by scanning over its output with an effectful accumulator function. + * Transforms a channel statefully by scanning over its output with an effectful accumulator function. * Emits the intermediate results of the scan operation. * - * @example + * **When to use** + * + * Use when maintaining accumulated state over channel output requires Effects + * or can fail, while still emitting each intermediate state. + * + * **Example** (Scanning channel output with effects) + * * ```ts * import { Channel, Data, Effect } from "effect" * @@ -2985,8 +3547,8 @@ export declare const scanEffect: { * ) * ``` * - * @since 2.0.0 - * @category Sequencing + * @category sequencing + * @since 4.0.0 */ (self: Channel, initial: S, f: (s: S, a: Types.NoInfer) => Effect.Effect): Channel; }; @@ -2994,7 +3556,8 @@ export declare const scanEffect: { * Catches any cause of failure from the channel and allows recovery by * creating a new channel based on the caught cause. * - * @example + * **Example** (Recovering from failure causes) + * * ```ts * import { Cause, Channel, Data } from "effect" * @@ -3022,15 +3585,16 @@ export declare const scanEffect: { * // The channel recovers gracefully from errors * ``` * - * @since 4.0.0 - * @category Error handling + * @category error handling + * @since 2.0.0 */ export declare const catchCause: { /** * Catches any cause of failure from the channel and allows recovery by * creating a new channel based on the caught cause. * - * @example + * **Example** (Recovering from failure causes) + * * ```ts * import { Cause, Channel, Data } from "effect" * @@ -3058,15 +3622,16 @@ export declare const catchCause: { * // The channel recovers gracefully from errors * ``` * - * @since 4.0.0 - * @category Error handling + * @category error handling + * @since 2.0.0 */ (f: (d: Cause.Cause) => Channel): (self: Channel) => Channel; /** * Catches any cause of failure from the channel and allows recovery by * creating a new channel based on the caught cause. * - * @example + * **Example** (Recovering from failure causes) + * * ```ts * import { Cause, Channel, Data } from "effect" * @@ -3094,24 +3659,63 @@ export declare const catchCause: { * // The channel recovers gracefully from errors * ``` * - * @since 4.0.0 - * @category Error handling + * @category error handling + * @since 2.0.0 */ (self: Channel, f: (d: Cause.Cause) => Channel): Channel; }; /** + * Runs an effect with the full failure `Cause` when the channel fails, then + * fails the returned channel with the original cause. + * + * **When to use** + * + * Use when observing the full channel failure `Cause` is needed without + * changing successful output or replacing the original cause. + * + * **Details** + * + * Use this for observing failures, such as logging or metrics. If the observer + * effect fails, that failure can fail the returned channel. + * + * @category error handling * @since 4.0.0 - * @category Error handling */ export declare const tapCause: { /** + * Runs an effect with the full failure `Cause` when the channel fails, then + * fails the returned channel with the original cause. + * + * **When to use** + * + * Use when observing the full channel failure `Cause` is needed without + * changing successful output or replacing the original cause. + * + * **Details** + * + * Use this for observing failures, such as logging or metrics. If the observer + * effect fails, that failure can fail the returned channel. + * + * @category error handling * @since 4.0.0 - * @category Error handling */ (f: (d: Cause.Cause) => Effect.Effect): (self: Channel) => Channel; /** + * Runs an effect with the full failure `Cause` when the channel fails, then + * fails the returned channel with the original cause. + * + * **When to use** + * + * Use when observing the full channel failure `Cause` is needed without + * changing successful output or replacing the original cause. + * + * **Details** + * + * Use this for observing failures, such as logging or metrics. If the observer + * effect fails, that failure can fail the returned channel. + * + * @category error handling * @since 4.0.0 - * @category Error handling */ (self: Channel, f: (d: Cause.Cause) => Effect.Effect): Channel; }; @@ -3119,40 +3723,139 @@ export declare const tapCause: { * Catches causes of failure that match a specific filter, allowing * conditional error recovery based on the type of failure. * + * **When to use** + * + * Use to recover a channel only when its full `Cause` satisfies a boolean + * predicate. + * + * **Details** + * + * When the predicate matches, the recovery function receives the original + * cause. When it does not match, the returned channel fails with the original + * cause. + * + * @see {@link catchCauseFilter} for selecting causes with a `Filter` + * @see {@link catchCause} for recovering from every cause + * @see {@link catchIf} for recovering from typed channel errors + * + * @category error handling * @since 4.0.0 - * @category Error handling */ export declare const catchCauseIf: { /** * Catches causes of failure that match a specific filter, allowing * conditional error recovery based on the type of failure. * + * **When to use** + * + * Use to recover a channel only when its full `Cause` satisfies a boolean + * predicate. + * + * **Details** + * + * When the predicate matches, the recovery function receives the original + * cause. When it does not match, the returned channel fails with the original + * cause. + * + * @see {@link catchCauseFilter} for selecting causes with a `Filter` + * @see {@link catchCause} for recovering from every cause + * @see {@link catchIf} for recovering from typed channel errors + * + * @category error handling * @since 4.0.0 - * @category Error handling */ (predicate: Predicate.Predicate>, f: (cause: Cause.Cause) => Channel): (self: Channel) => Channel; /** * Catches causes of failure that match a specific filter, allowing * conditional error recovery based on the type of failure. * + * **When to use** + * + * Use to recover a channel only when its full `Cause` satisfies a boolean + * predicate. + * + * **Details** + * + * When the predicate matches, the recovery function receives the original + * cause. When it does not match, the returned channel fails with the original + * cause. + * + * @see {@link catchCauseFilter} for selecting causes with a `Filter` + * @see {@link catchCause} for recovering from every cause + * @see {@link catchIf} for recovering from typed channel errors + * + * @category error handling * @since 4.0.0 - * @category Error handling */ (self: Channel, predicate: Predicate.Predicate>, f: (cause: Cause.Cause) => Channel): Channel; }; /** + * Recovers from channel failures whose full `Cause` is selected by a `Filter`. + * + * **When to use** + * + * Use when you need to recover a channel only from causes selected by a + * `Filter`, while giving the recovery both the selected value and the original + * `Cause`. + * + * **Details** + * + * When the filter succeeds, the recovery function receives the selected value + * and the original cause. When the filter fails, the returned channel fails + * with the residual cause produced by the filter. + * + * @see {@link catchCauseIf} for selecting causes with a predicate + * @see {@link catchFilter} for selecting typed errors with a `Filter` + * @see {@link catchCause} for recovering from every cause + * + * @category error handling * @since 4.0.0 - * @category Error handling */ export declare const catchCauseFilter: { /** + * Recovers from channel failures whose full `Cause` is selected by a `Filter`. + * + * **When to use** + * + * Use when you need to recover a channel only from causes selected by a + * `Filter`, while giving the recovery both the selected value and the original + * `Cause`. + * + * **Details** + * + * When the filter succeeds, the recovery function receives the selected value + * and the original cause. When the filter fails, the returned channel fails + * with the residual cause produced by the filter. + * + * @see {@link catchCauseIf} for selecting causes with a predicate + * @see {@link catchFilter} for selecting typed errors with a `Filter` + * @see {@link catchCause} for recovering from every cause + * + * @category error handling * @since 4.0.0 - * @category Error handling */ , OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1>(filter: Filter.Filter, EB, X>, f: (failure: EB, cause: Cause.Cause) => Channel): (self: Channel) => Channel | OutErr1, OutDone | OutDone1, InElem & InElem1, InErr & InErr1, InDone & InDone1, Env | Env1>; /** + * Recovers from channel failures whose full `Cause` is selected by a `Filter`. + * + * **When to use** + * + * Use when you need to recover a channel only from causes selected by a + * `Filter`, while giving the recovery both the selected value and the original + * `Cause`. + * + * **Details** + * + * When the filter succeeds, the recovery function receives the selected value + * and the original cause. When the filter fails, the returned channel fails + * with the residual cause produced by the filter. + * + * @see {@link catchCauseIf} for selecting causes with a predicate + * @see {@link catchFilter} for selecting typed errors with a `Filter` + * @see {@link catchCause} for recovering from every cause + * + * @category error handling * @since 4.0.0 - * @category Error handling */ , OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1>(self: Channel, filter: Filter.Filter, EB, X>, f: (failure: EB, cause: Cause.Cause) => Channel): Channel | OutErr1, OutDone | OutDone1, InElem & InElem1, InErr & InErr1, InDone & InDone1, Env | Env1>; }; @@ -3162,88 +3865,280 @@ declare const catch_: { }; export { /** + * Recovers from typed channel errors by running a fallback channel. + * + * @category error handling * @since 4.0.0 - * @category Error handling */ catch_ as catch }; /** + * Runs an effect when the channel fails with a typed error, then preserves the + * original channel failure. + * + * **Details** + * + * The effect is not run for normal channel completion. If the observer effect + * fails, that failure can fail the returned channel. + * + * @category error handling * @since 4.0.0 - * @category Error handling */ export declare const tapError: { /** + * Runs an effect when the channel fails with a typed error, then preserves the + * original channel failure. + * + * **Details** + * + * The effect is not run for normal channel completion. If the observer effect + * fails, that failure can fail the returned channel. + * + * @category error handling * @since 4.0.0 - * @category Error handling */ (f: (d: OutErr) => Effect.Effect): (self: Channel) => Channel; /** + * Runs an effect when the channel fails with a typed error, then preserves the + * original channel failure. + * + * **Details** + * + * The effect is not run for normal channel completion. If the observer effect + * fails, that failure can fail the returned channel. + * + * @category error handling * @since 4.0.0 - * @category Error handling */ (self: Channel, f: (d: OutErr) => Effect.Effect): Channel; }; /** + * Recovers from typed channel errors that match a predicate or refinement. + * + * **When to use** + * + * Use to recover from typed channel errors when a predicate or refinement + * selects the failures that should switch to a recovery channel. + * + * **Details** + * + * Matching errors are handled by the recovery function. Non-matching errors + * are handled by `orElse` when provided. Without `orElse`, non-matching errors + * are re-failed. + * + * @see {@link catch_ catch} for recovering from every typed channel error + * @see {@link catchFilter} for selecting typed errors with a `Filter` + * @see {@link catchTag} for selecting tagged typed errors + * @see {@link catchCauseFilter} for selecting full causes with a `Filter` + * + * @category error handling * @since 4.0.0 - * @category Error handling */ export declare const catchIf: { /** + * Recovers from typed channel errors that match a predicate or refinement. + * + * **When to use** + * + * Use to recover from typed channel errors when a predicate or refinement + * selects the failures that should switch to a recovery channel. + * + * **Details** + * + * Matching errors are handled by the recovery function. Non-matching errors + * are handled by `orElse` when provided. Without `orElse`, non-matching errors + * are re-failed. + * + * @see {@link catch_ catch} for recovering from every typed channel error + * @see {@link catchFilter} for selecting typed errors with a `Filter` + * @see {@link catchTag} for selecting tagged typed errors + * @see {@link catchCauseFilter} for selecting full causes with a `Filter` + * + * @category error handling * @since 4.0.0 - * @category Error handling */ - , OutDone2 = never, InElem2 = unknown, InErr2 = unknown, InDone2 = unknown, Env2 = never>(refinement: Predicate.Refinement, f: (failure: EB) => Channel, orElse?: ((failure: Exclude) => Channel) | undefined): (self: Channel) => Channel; + (refinement: Predicate.Refinement, f: (failure: EB) => Channel, orElse?: ((failure: Exclude) => Channel) | undefined): (self: Channel) => Channel, OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? Exclude : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; /** + * Recovers from typed channel errors that match a predicate or refinement. + * + * **When to use** + * + * Use to recover from typed channel errors when a predicate or refinement + * selects the failures that should switch to a recovery channel. + * + * **Details** + * + * Matching errors are handled by the recovery function. Non-matching errors + * are handled by `orElse` when provided. Without `orElse`, non-matching errors + * are re-failed. + * + * @see {@link catch_ catch} for recovering from every typed channel error + * @see {@link catchFilter} for selecting typed errors with a `Filter` + * @see {@link catchTag} for selecting tagged typed errors + * @see {@link catchCauseFilter} for selecting full causes with a `Filter` + * + * @category error handling * @since 4.0.0 - * @category Error handling */ - (predicate: Predicate.Predicate, f: (failure: OutErr) => Channel, orElse?: ((failure: OutErr) => Channel) | undefined): (self: Channel) => Channel; + (predicate: Predicate.Predicate, f: (failure: OutErr) => Channel, orElse?: ((failure: OutErr) => Channel) | undefined): (self: Channel) => Channel, OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? OutErr : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; /** + * Recovers from typed channel errors that match a predicate or refinement. + * + * **When to use** + * + * Use to recover from typed channel errors when a predicate or refinement + * selects the failures that should switch to a recovery channel. + * + * **Details** + * + * Matching errors are handled by the recovery function. Non-matching errors + * are handled by `orElse` when provided. Without `orElse`, non-matching errors + * are re-failed. + * + * @see {@link catch_ catch} for recovering from every typed channel error + * @see {@link catchFilter} for selecting typed errors with a `Filter` + * @see {@link catchTag} for selecting tagged typed errors + * @see {@link catchCauseFilter} for selecting full causes with a `Filter` + * + * @category error handling * @since 4.0.0 - * @category Error handling */ - , OutDone2 = never, InElem2 = unknown, InErr2 = unknown, InDone2 = unknown, Env2 = never>(self: Channel, refinement: Predicate.Refinement, f: (failure: EB) => Channel, orElse?: ((failure: Exclude) => Channel) | undefined): Channel; + (self: Channel, refinement: Predicate.Refinement, f: (failure: EB) => Channel, orElse?: ((failure: Exclude) => Channel) | undefined): Channel, OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? Exclude : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; /** + * Recovers from typed channel errors that match a predicate or refinement. + * + * **When to use** + * + * Use to recover from typed channel errors when a predicate or refinement + * selects the failures that should switch to a recovery channel. + * + * **Details** + * + * Matching errors are handled by the recovery function. Non-matching errors + * are handled by `orElse` when provided. Without `orElse`, non-matching errors + * are re-failed. + * + * @see {@link catch_ catch} for recovering from every typed channel error + * @see {@link catchFilter} for selecting typed errors with a `Filter` + * @see {@link catchTag} for selecting tagged typed errors + * @see {@link catchCauseFilter} for selecting full causes with a `Filter` + * + * @category error handling * @since 4.0.0 - * @category Error handling */ - (self: Channel, predicate: Predicate.Predicate, f: (failure: OutErr) => Channel, orElse?: ((failure: OutErr) => Channel) | undefined): Channel; + (self: Channel, predicate: Predicate.Predicate, f: (failure: OutErr) => Channel, orElse?: ((failure: OutErr) => Channel) | undefined): Channel, OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? OutErr : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; }; /** + * Recovers from typed channel errors selected by a `Filter`. + * + * **When to use** + * + * Use to recover from channel errors with a reusable `Filter` when matching + * can also narrow or transform the error before choosing the recovery channel. + * + * **Details** + * + * Successful filter results are handled by the recovery function. Failed + * filter results are handled by `orElse` when provided. Without `orElse`, + * failed filter results are re-failed. + * + * @see {@link catchIf} for selecting typed errors with a predicate + * @see {@link catchTag} for selecting tagged typed errors + * @see {@link catchCauseFilter} for selecting full causes with a `Filter` + * + * @category error handling * @since 4.0.0 - * @category Error handling */ export declare const catchFilter: { /** + * Recovers from typed channel errors selected by a `Filter`. + * + * **When to use** + * + * Use to recover from channel errors with a reusable `Filter` when matching + * can also narrow or transform the error before choosing the recovery channel. + * + * **Details** + * + * Successful filter results are handled by the recovery function. Failed + * filter results are handled by `orElse` when provided. Without `orElse`, + * failed filter results are re-failed. + * + * @see {@link catchIf} for selecting typed errors with a predicate + * @see {@link catchTag} for selecting tagged typed errors + * @see {@link catchCauseFilter} for selecting full causes with a `Filter` + * + * @category error handling * @since 4.0.0 - * @category Error handling */ - (filter: Filter.Filter, f: (failure: EB) => Channel, orElse?: ((failure: X) => Channel) | undefined): (self: Channel) => Channel; + (filter: Filter.Filter, f: (failure: EB) => Channel, orElse?: ((failure: X) => Channel) | undefined): (self: Channel) => Channel, OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? X : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; /** + * Recovers from typed channel errors selected by a `Filter`. + * + * **When to use** + * + * Use to recover from channel errors with a reusable `Filter` when matching + * can also narrow or transform the error before choosing the recovery channel. + * + * **Details** + * + * Successful filter results are handled by the recovery function. Failed + * filter results are handled by `orElse` when provided. Without `orElse`, + * failed filter results are re-failed. + * + * @see {@link catchIf} for selecting typed errors with a predicate + * @see {@link catchTag} for selecting tagged typed errors + * @see {@link catchCauseFilter} for selecting full causes with a `Filter` + * + * @category error handling * @since 4.0.0 - * @category Error handling */ - (self: Channel, filter: Filter.Filter, f: (failure: EB) => Channel, orElse?: ((failure: X) => Channel) | undefined): Channel; + (self: Channel, filter: Filter.Filter, f: (failure: EB) => Channel, orElse?: ((failure: X) => Channel) | undefined): Channel, OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? X : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; }; /** + * Recovers from tagged channel errors whose `_tag` matches one or more tags. + * + * **Details** + * + * Matching tagged errors are handled by the recovery function. Non-matching + * errors are handled by `orElse` when provided. Without `orElse`, + * non-matching errors are re-failed. + * + * @category error handling * @since 4.0.0 - * @category Error handling */ export declare const catchTag: { /** + * Recovers from tagged channel errors whose `_tag` matches one or more tags. + * + * **Details** + * + * Matching tagged errors are handled by the recovery function. Non-matching + * errors are handled by `orElse` when provided. Without `orElse`, + * non-matching errors are re-failed. + * + * @category error handling * @since 4.0.0 - * @category Error handling */ - | Arr.NonEmptyReadonlyArray>, OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1, OutElem2 = never, OutErr2 = Types.ExcludeTag ? K[number] : K>, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, InDone2 = unknown, Env2 = never>(k: K, f: (e: Types.ExtractTag, K extends Arr.NonEmptyReadonlyArray ? K[number] : K>) => Channel, orElse?: ((e: Types.ExcludeTag, K extends Arr.NonEmptyReadonlyArray ? K[number] : K>) => Channel) | undefined): (self: Channel) => Channel; + | Arr.NonEmptyReadonlyArray>, OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1, OutElem2 = Types.unassigned, OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, InDone2 = unknown, Env2 = never>(k: K, f: (e: Types.ExtractTag, K extends Arr.NonEmptyReadonlyArray ? K[number] : K>) => Channel, orElse?: ((e: Types.ExcludeTag, K extends Arr.NonEmptyReadonlyArray ? K[number] : K>) => Channel) | undefined): (self: Channel) => Channel, OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? Types.ExcludeTag ? K[number] : K> : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; /** + * Recovers from tagged channel errors whose `_tag` matches one or more tags. + * + * **Details** + * + * Matching tagged errors are handled by the recovery function. Non-matching + * errors are handled by `orElse` when provided. Without `orElse`, + * non-matching errors are re-failed. + * + * @category error handling * @since 4.0.0 - * @category Error handling */ - | Arr.NonEmptyReadonlyArray>, OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1, OutElem2 = never, OutErr2 = Types.ExcludeTag ? K[number] : K>, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, InDone2 = unknown, Env2 = never>(self: Channel, k: K, f: (e: Types.ExtractTag, K extends Arr.NonEmptyReadonlyArray ? K[number] : K>) => Channel, orElse?: ((e: Types.ExcludeTag, K extends Arr.NonEmptyReadonlyArray ? K[number] : K>) => Channel) | undefined): Channel; + | Arr.NonEmptyReadonlyArray>, OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1, OutElem2 = Types.unassigned, OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, InDone2 = unknown, Env2 = never>(self: Channel, k: K, f: (e: Types.ExtractTag, K extends Arr.NonEmptyReadonlyArray ? K[number] : K>) => Channel, orElse?: ((e: Types.ExcludeTag, K extends Arr.NonEmptyReadonlyArray ? K[number] : K>) => Channel) | undefined): Channel, OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? Types.ExcludeTag ? K[number] : K> : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; }; /** * Catches a specific reason within a tagged error. * - * @example + * **Example** (Recovering from nested reasons) + * * ```ts * import { Channel, Data } from "effect" * @@ -3270,14 +4165,15 @@ export declare const catchTag: { * ) * ``` * + * @category error handling * @since 4.0.0 - * @category Error handling */ export declare const catchReason: { /** * Catches a specific reason within a tagged error. * - * @example + * **Example** (Recovering from nested reasons) + * * ```ts * import { Channel, Data } from "effect" * @@ -3304,14 +4200,15 @@ export declare const catchReason: { * ) * ``` * + * @category error handling * @since 4.0.0 - * @category Error handling */ - , RK extends Types.ReasonTags, K>>, OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1, OutElem2 = Types.unassigned, OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, InDone2 = unknown, Env2 = never>(errorTag: K, reasonTag: RK, f: (reason: Types.ExtractReason, K>, RK>, error: Types.NarrowReason, K>, RK>) => Channel, orElse?: ((reason: Types.ExcludeReason, K>, RK>, error: Types.OmitReason, K>, RK>) => Channel) | undefined): (self: Channel) => Channel, (OutElem2 extends Types.unassigned ? OutErr : Types.ExcludeTag) | OutErr1 | OutErr2, OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; + , RK extends Types.ReasonTags, K>>, OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1, OutElem2 = Types.unassigned, OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, InDone2 = unknown, Env2 = never>(errorTag: K, reasonTag: RK, f: (reason: Types.ExtractReason, K>, RK>, error: Types.NarrowReason, K>, RK>) => Channel, orElse?: ((reason: Types.ExcludeReason, K>, RK>, error: Types.OmitReason, K>, RK>) => Channel) | undefined): (self: Channel) => Channel, Types.ExcludeTag | OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? Types.ExtractTag : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; /** * Catches a specific reason within a tagged error. * - * @example + * **Example** (Recovering from nested reasons) + * * ```ts * import { Channel, Data } from "effect" * @@ -3338,29 +4235,29 @@ export declare const catchReason: { * ) * ``` * + * @category error handling * @since 4.0.0 - * @category Error handling */ - , RK extends Types.ReasonTags, K>>, OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1, OutElem2 = Types.unassigned, OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, InDone2 = unknown, Env2 = never>(self: Channel, errorTag: K, reasonTag: RK, f: (reason: Types.ExtractReason, K>, RK>, error: Types.NarrowReason, K>, RK>) => Channel, orElse?: ((reason: Types.ExcludeReason, K>, RK>, error: Types.OmitReason, K>, RK>) => Channel) | undefined): Channel, (OutElem2 extends Types.unassigned ? OutErr : Types.ExcludeTag) | OutErr1 | OutErr2, OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; + , RK extends Types.ReasonTags, K>>, OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1, OutElem2 = Types.unassigned, OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, InDone2 = unknown, Env2 = never>(self: Channel, errorTag: K, reasonTag: RK, f: (reason: Types.ExtractReason, K>, RK>, error: Types.NarrowReason, K>, RK>) => Channel, orElse?: ((reason: Types.ExcludeReason, K>, RK>, error: Types.OmitReason, K>, RK>) => Channel) | undefined): Channel, Types.ExcludeTag | OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? Types.ExtractTag : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; }; /** * Catches multiple reasons within a tagged error using an object of handlers. * + * @category error handling * @since 4.0.0 - * @category Error handling */ export declare const catchReasons: { /** * Catches multiple reasons within a tagged error using an object of handlers. * + * @category error handling * @since 4.0.0 - * @category Error handling */ , OutErr, Cases extends { [RK in Types.ReasonTags, K>>]+?: (reason: Types.ExtractReason, K>, RK>, error: Types.NarrowReason, K>, RK>) => Channel; }, OutElem2 = Types.unassigned, OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, InDone2 = unknown, Env2 = never>(errorTag: K, cases: Cases, orElse?: ((reason: Types.ExcludeReason, K>, Extract>, error: Types.OmitReason, K>, Extract>) => Channel) | undefined): (self: Channel) => Channel | { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? OutElem1 : never; - }[keyof Cases], (OutElem2 extends Types.unassigned ? OutErr : Types.ExcludeTag) | OutErr2 | { + }[keyof Cases], Types.ExcludeTag | OutErr2 | (OutElem2 extends Types.unassigned ? Types.ExtractTag : never) | { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? OutErr1 : never; }[keyof Cases], OutDone | OutDone2 | { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? OutDone1 : never; @@ -3376,14 +4273,14 @@ export declare const catchReasons: { /** * Catches multiple reasons within a tagged error using an object of handlers. * + * @category error handling * @since 4.0.0 - * @category Error handling */ , Cases extends { [RK in Types.ReasonTags>]+?: (reason: Types.ExtractReason, RK>, error: Types.NarrowReason, RK>) => Channel; }, OutElem2 = Types.unassigned, OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, InDone2 = unknown, Env2 = never>(self: Channel, errorTag: K, cases: Cases, orElse?: ((reason: Types.ExcludeReason, K>, Extract>, error: Types.OmitReason, K>, Extract>) => Channel) | undefined): Channel | { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? OutElem1 : never; - }[keyof Cases], (OutElem2 extends Types.unassigned ? OutErr : Types.ExcludeTag) | OutErr2 | { + }[keyof Cases], Types.ExcludeTag | OutErr2 | (OutElem2 extends Types.unassigned ? Types.ExtractTag : never) | { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? OutErr1 : never; }[keyof Cases], OutDone | OutDone2 | { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? OutDone1 : never; @@ -3400,7 +4297,8 @@ export declare const catchReasons: { /** * Promotes nested reason errors into the channel error, replacing the parent error. * - * @example + * **Example** (Promoting nested reasons) + * * ```ts * import { Channel, Data } from "effect" * @@ -3423,14 +4321,15 @@ export declare const catchReasons: { * const unwrapped = channel.pipe(Channel.unwrapReason("AiError")) * ``` * + * @category error handling * @since 4.0.0 - * @category Error handling */ export declare const unwrapReason: { /** * Promotes nested reason errors into the channel error, replacing the parent error. * - * @example + * **Example** (Promoting nested reasons) + * * ```ts * import { Channel, Data } from "effect" * @@ -3453,14 +4352,15 @@ export declare const unwrapReason: { * const unwrapped = channel.pipe(Channel.unwrapReason("AiError")) * ``` * + * @category error handling * @since 4.0.0 - * @category Error handling */ , OutErr>(errorTag: K): (self: Channel) => Channel | Types.ReasonOf>, OutDone, InElem, InErr, InDone, Env>; /** * Promotes nested reason errors into the channel error, replacing the parent error. * - * @example + * **Example** (Promoting nested reasons) + * * ```ts * import { Channel, Data } from "effect" * @@ -3483,8 +4383,8 @@ export declare const unwrapReason: { * const unwrapped = channel.pipe(Channel.unwrapReason("AiError")) * ``` * + * @category error handling * @since 4.0.0 - * @category Error handling */ >(self: Channel, errorTag: K): Channel | Types.ReasonOf>, OutDone, InElem, InErr, InDone, Env>; }; @@ -3493,8 +4393,8 @@ export declare const unwrapReason: { * value of the returned channel is created by applying the specified function * to the failure value of this channel. * + * @category error handling * @since 2.0.0 - * @category Error handling */ export declare const mapError: { /** @@ -3502,8 +4402,8 @@ export declare const mapError: { * value of the returned channel is created by applying the specified function * to the failure value of this channel. * + * @category error handling * @since 2.0.0 - * @category Error handling */ (f: (err: OutErr) => OutErr2): (self: Channel) => Channel; /** @@ -3511,8 +4411,8 @@ export declare const mapError: { * value of the returned channel is created by applying the specified function * to the failure value of this channel. * + * @category error handling * @since 2.0.0 - * @category Error handling */ (self: Channel, f: (err: OutErr) => OutErr2): Channel; }; @@ -3520,7 +4420,8 @@ export declare const mapError: { * Converts all errors in the channel to defects (unrecoverable failures). * This is useful when you want to treat errors as programming errors. * - * @example + * **Example** (Converting failures to defects) + * * ```ts * import { Channel, Data } from "effect" * @@ -3537,17 +4438,19 @@ export declare const mapError: { * // Any failure will now become a defect (uncaught exception) * ``` * - * @since 4.0.0 - * @category Error handling + * @category error handling + * @since 2.0.0 */ export declare const orDie: (self: Channel) => Channel; /** * Ignores all errors in the channel, converting them to an empty channel. * + * **Details** + * * Use the `log` option to emit the full {@link Cause} when the channel fails. * + * @category error handling * @since 4.0.0 - * @category Error handling */ export declare const ignore: | { readonly log?: boolean | Severity | undefined; @@ -3561,10 +4464,17 @@ export declare const ignore: | { readonly log?: boolean | Severity | undefined; @@ -3579,35 +4489,39 @@ export declare const ignoreCause: (schedule: Schedule.Schedule, SE, SR> | (($: (_: Schedule.Schedule, SE, SR>) => Schedule.Schedule) => Schedule.Schedule, SE, SR>)): (self: Channel) => Channel; /** * Returns a new channel that retries this channel according to the specified * schedule whenever it fails. * + * @category error handling * @since 4.0.0 - * @category utils */ (self: Channel, schedule: Schedule.Schedule | (($: (_: Schedule.Schedule, SE, SR>) => Schedule.Schedule) => Schedule.Schedule, SE, SR>)): Channel; }; /** - * Returns a new channel, which sequentially combines this channel, together - * with the provided factory function, which creates a second channel based on - * the output values of this channel. The result is a channel that will first - * perform the functions of this channel, before performing the functions of - * the created channel (including yielding its terminal value). + * Maps each output element to a channel and emits values from the most recent + * active child channels. + * + * **Details** + * + * With the default concurrency of `1`, starting a new child channel interrupts + * the previous child channel. Use `options.concurrency` to allow more active + * child channels. The source channel's done value is preserved. + * + * **Example** (Switching mapped channels) * - * @example * ```ts * import { Channel, Data } from "effect" * @@ -3627,18 +4541,22 @@ export declare const retry: { * // Outputs: "value-1", "value-2", "value-3" * ``` * - * @since 2.0.0 * @category sequencing + * @since 4.0.0 */ export declare const switchMap: { /** - * Returns a new channel, which sequentially combines this channel, together - * with the provided factory function, which creates a second channel based on - * the output values of this channel. The result is a channel that will first - * perform the functions of this channel, before performing the functions of - * the created channel (including yielding its terminal value). + * Maps each output element to a channel and emits values from the most recent + * active child channels. + * + * **Details** + * + * With the default concurrency of `1`, starting a new child channel interrupts + * the previous child channel. Use `options.concurrency` to allow more active + * child channels. The source channel's done value is preserved. + * + * **Example** (Switching mapped channels) * - * @example * ```ts * import { Channel, Data } from "effect" * @@ -3658,21 +4576,25 @@ export declare const switchMap: { * // Outputs: "value-1", "value-2", "value-3" * ``` * - * @since 2.0.0 * @category sequencing + * @since 4.0.0 */ (f: (d: OutElem) => Channel, options?: { readonly concurrency?: number | "unbounded" | undefined; readonly bufferSize?: number | undefined; }): (self: Channel) => Channel; /** - * Returns a new channel, which sequentially combines this channel, together - * with the provided factory function, which creates a second channel based on - * the output values of this channel. The result is a channel that will first - * perform the functions of this channel, before performing the functions of - * the created channel (including yielding its terminal value). + * Maps each output element to a channel and emits values from the most recent + * active child channels. + * + * **Details** + * + * With the default concurrency of `1`, starting a new child channel interrupts + * the previous child channel. Use `options.concurrency` to allow more active + * child channels. The source channel's done value is preserved. + * + * **Example** (Switching mapped channels) * - * @example * ```ts * import { Channel, Data } from "effect" * @@ -3692,8 +4614,8 @@ export declare const switchMap: { * // Outputs: "value-1", "value-2", "value-3" * ``` * - * @since 2.0.0 * @category sequencing + * @since 4.0.0 */ (self: Channel, f: (d: OutElem) => Channel, options?: { readonly concurrency?: number | "unbounded" | undefined; @@ -3703,7 +4625,13 @@ export declare const switchMap: { /** * Merges multiple channels with specified concurrency and buffering options. * - * @example + * **When to use** + * + * Use when channel outputs are themselves channels and multiple inner channels + * should run with configured concurrency and buffering. + * + * **Example** (Merging nested channels) + * * ```ts * import { Channel, Data } from "effect" * @@ -3727,14 +4655,20 @@ export declare const switchMap: { * // Outputs: 1, 2, 3, 4, 5, 6 (order may vary due to concurrency) * ``` * + * @category combining * @since 2.0.0 - * @category utils */ export declare const mergeAll: { /** * Merges multiple channels with specified concurrency and buffering options. * - * @example + * **When to use** + * + * Use when channel outputs are themselves channels and multiple inner channels + * should run with configured concurrency and buffering. + * + * **Example** (Merging nested channels) + * * ```ts * import { Channel, Data } from "effect" * @@ -3758,8 +4692,8 @@ export declare const mergeAll: { * // Outputs: 1, 2, 3, 4, 5, 6 (order may vary due to concurrency) * ``` * + * @category combining * @since 2.0.0 - * @category utils */ (options: { readonly concurrency: number | "unbounded"; @@ -3769,7 +4703,13 @@ export declare const mergeAll: { /** * Merges multiple channels with specified concurrency and buffering options. * - * @example + * **When to use** + * + * Use when channel outputs are themselves channels and multiple inner channels + * should run with configured concurrency and buffering. + * + * **Example** (Merging nested channels) + * * ```ts * import { Channel, Data } from "effect" * @@ -3793,8 +4733,8 @@ export declare const mergeAll: { * // Outputs: 1, 2, 3, 4, 5, 6 (order may vary due to concurrency) * ``` * + * @category combining * @since 2.0.0 - * @category utils */ (channels: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>, options: { readonly concurrency: number | "unbounded"; @@ -3805,7 +4745,8 @@ export declare const mergeAll: { /** * Represents strategies for halting merged channels when one completes or fails. * - * @example + * **Example** (Choosing merge halt strategies) + * * ```ts * import type { Channel } from "effect" * @@ -3816,15 +4757,16 @@ export declare const mergeAll: { * const either: Channel.HaltStrategy = "either" // Stop when either channel halts * ``` * - * @since 2.0.0 * @category models + * @since 4.0.0 */ export type HaltStrategy = "left" | "right" | "both" | "either"; /** * Returns a new channel, which is the merge of this channel and the specified * channel. * - * @example + * **Example** (Merging channels) + * * ```ts * import { Channel, Data } from "effect" * @@ -3845,15 +4787,16 @@ export type HaltStrategy = "left" | "right" | "both" | "either"; * // Order may vary: 1, "a", 2, "b", 3, "c" * ``` * - * @since 2.0.0 - * @category utils + * @category combining + * @since 4.0.0 */ export declare const merge: { /** * Returns a new channel, which is the merge of this channel and the specified * channel. * - * @example + * **Example** (Merging channels) + * * ```ts * import { Channel, Data } from "effect" * @@ -3874,8 +4817,8 @@ export declare const merge: { * // Order may vary: 1, "a", 2, "b", 3, "c" * ``` * - * @since 2.0.0 - * @category utils + * @category combining + * @since 4.0.0 */ (right: Channel, options?: { readonly haltStrategy?: HaltStrategy | undefined; @@ -3884,7 +4827,8 @@ export declare const merge: { * Returns a new channel, which is the merge of this channel and the specified * channel. * - * @example + * **Example** (Merging channels) + * * ```ts * import { Channel, Data } from "effect" * @@ -3905,26 +4849,65 @@ export declare const merge: { * // Order may vary: 1, "a", 2, "b", 3, "c" * ``` * - * @since 2.0.0 - * @category utils + * @category combining + * @since 4.0.0 */ (left: Channel, right: Channel, options?: { readonly haltStrategy?: HaltStrategy | undefined; } | undefined): Channel; }; /** + * Runs an effect concurrently with a channel while emitting only the channel's + * output elements. + * + * **When to use** + * + * Use when a side effect should run for the lifetime of a channel and only the + * channel's output elements should be emitted. + * + * **Details** + * + * The effect's successful value is ignored. If the effect fails while the + * channel is running, the returned channel fails with that error. + * + * @category combining * @since 4.0.0 - * @category utils */ export declare const mergeEffect: { /** + * Runs an effect concurrently with a channel while emitting only the channel's + * output elements. + * + * **When to use** + * + * Use when a side effect should run for the lifetime of a channel and only the + * channel's output elements should be emitted. + * + * **Details** + * + * The effect's successful value is ignored. If the effect fails while the + * channel is running, the returned channel fails with that error. + * + * @category combining * @since 4.0.0 - * @category utils */ (effect: Effect.Effect): (self: Channel) => Channel; /** + * Runs an effect concurrently with a channel while emitting only the channel's + * output elements. + * + * **When to use** + * + * Use when a side effect should run for the lifetime of a channel and only the + * channel's output elements should be emitted. + * + * **Details** + * + * The effect's successful value is ignored. If the effect fails while the + * channel is running, the returned channel fails with that error. + * + * @category combining * @since 4.0.0 - * @category utils */ (self: Channel, effect: Effect.Effect): Channel; }; @@ -3933,12 +4916,14 @@ export declare const mergeEffect: { * standalone `\r` as line terminators. The behavior matches * `String.linesIterator` regardless of how the input is chunked. * + * **Details** + * * A line terminator at the very end of the stream does **not** produce a * trailing empty line (consistent with `String.linesIterator`). Conversely, * if the stream ends without a terminator the final partial line is still * emitted. * - * **Example** + * **Example** (Splitting string chunks into lines) * * ```ts * import { Effect, Stream } from "effect" @@ -3952,18 +4937,32 @@ export declare const mergeEffect: { * })) * ``` * - * @since 2.0.0 * @category String manipulation + * @since 2.0.0 */ export declare const splitLines: () => Channel, Err, Done, Arr.NonEmptyReadonlyArray, Err, Done>; /** - * @since 4.0.0 + * Decodes incoming `Uint8Array` chunks into strings using `TextDecoder`. + * + * **Details** + * + * Input chunks are decoded with streaming enabled so multi-byte characters may + * span `Uint8Array` boundaries. The optional `encoding` and `options` are + * passed to `TextDecoder`. + * * @category String manipulation + * @since 4.0.0 */ export declare const decodeText: (encoding?: string, options?: TextDecoderOptions) => Channel, Err, Done, Arr.NonEmptyReadonlyArray, Err, Done>; /** - * @since 4.0.0 + * Encodes incoming string chunks into `Uint8Array` values using `TextEncoder`. + * + * **Details** + * + * Each string inside an emitted array is encoded independently. + * * @category String manipulation + * @since 4.0.0 */ export declare const encodeText: () => Channel, Err, Done, Arr.NonEmptyReadonlyArray, Err, Done>; /** @@ -3972,7 +4971,8 @@ export declare const encodeText: () => Channel() => Channel(that: Channel): (self: Channel) => Channel; /** @@ -4028,7 +5029,8 @@ export declare const pipeTo: { * and the output type of the specified channel, terminating with the value of * the specified channel. * - * @example + * **Example** (Piping one channel into another) + * * ```ts * import { Channel, Data } from "effect" * @@ -4046,8 +5048,8 @@ export declare const pipeTo: { * // Outputs: 2, 4, 6 * ``` * + * @category sequencing * @since 2.0.0 - * @category utils */ (self: Channel, that: Channel): Channel; }; @@ -4056,7 +5058,8 @@ export declare const pipeTo: { * specified channel and preserves this channel's failures without providing * them to the other channel for observation. * - * @example + * **Example** (Piping while preserving failures) + * * ```ts * import { Channel, Data } from "effect" * @@ -4074,8 +5077,8 @@ export declare const pipeTo: { * // Source errors are preserved and not sent to transform channel * ``` * + * @category sequencing * @since 2.0.0 - * @category utils */ export declare const pipeToOrFail: { /** @@ -4083,7 +5086,8 @@ export declare const pipeToOrFail: { * specified channel and preserves this channel's failures without providing * them to the other channel for observation. * - * @example + * **Example** (Piping while preserving failures) + * * ```ts * import { Channel, Data } from "effect" * @@ -4101,8 +5105,8 @@ export declare const pipeToOrFail: { * // Source errors are preserved and not sent to transform channel * ``` * + * @category sequencing * @since 2.0.0 - * @category utils */ (that: Channel): (self: Channel) => Channel; /** @@ -4110,7 +5114,8 @@ export declare const pipeToOrFail: { * specified channel and preserves this channel's failures without providing * them to the other channel for observation. * - * @example + * **Example** (Piping while preserving failures) + * * ```ts * import { Channel, Data } from "effect" * @@ -4128,8 +5133,8 @@ export declare const pipeToOrFail: { * // Source errors are preserved and not sent to transform channel * ``` * + * @category sequencing * @since 2.0.0 - * @category utils */ (self: Channel, that: Channel): Channel; }; @@ -4137,7 +5142,8 @@ export declare const pipeToOrFail: { * Constructs a `Channel` from a scoped effect that will result in a * `Channel` if successful. * - * @example + * **Example** (Unwrapping channel effects) + * * ```ts * import { Channel, Data, Effect } from "effect" * @@ -4156,105 +5162,174 @@ export declare const pipeToOrFail: { * // The resulting channel outputs: 1, 2, 3 * ``` * - * @since 2.0.0 * @category constructors + * @since 2.0.0 */ export declare const unwrap: (channel: Effect.Effect, E, R>) => Channel | R2>; /** + * Runs a channel with a scope provided for the duration of the channel + * execution, removing the channel's `Scope` requirement. + * + * @category resource management * @since 2.0.0 - * @category utils */ export declare const scoped: (self: Channel) => Channel>; /** - * Returns a new channel which embeds the given input handler into a Channel. + * Runs an input handler against the upstream pull while the wrapped channel + * runs without receiving upstream input directly. * - * @example - * ```ts - * import { Channel, Data, Effect } from "effect" + * **Details** * - * class EmbedError extends Data.TaggedError("EmbedError")<{ - * readonly stage: string - * }> {} + * The input handler is forked in the channel scope. The wrapped channel is run + * with an already-completed input. + * + * **Example** (Embedding custom input handling) + * + * ```ts + * import { Channel, Effect } from "effect" * * // Create a base channel * const baseChannel = Channel.fromIterable([1, 2, 3]) * - * // Embed input handling - simplified example + * // Drain the embedded input while the base channel runs * const embeddedChannel = Channel.embedInput( * baseChannel, - * (_upstream) => Effect.void + * (upstream) => + * upstream.pipe( + * Effect.tap((message) => + * Effect.sync(() => console.log(message)) + * ), + * Effect.forever, + * Effect.ignore + * ) * ) * ``` * + * @category sequencing * @since 2.0.0 - * @category utils */ export declare const embedInput: { /** - * Returns a new channel which embeds the given input handler into a Channel. + * Runs an input handler against the upstream pull while the wrapped channel + * runs without receiving upstream input directly. * - * @example - * ```ts - * import { Channel, Data, Effect } from "effect" + * **Details** * - * class EmbedError extends Data.TaggedError("EmbedError")<{ - * readonly stage: string - * }> {} + * The input handler is forked in the channel scope. The wrapped channel is run + * with an already-completed input. + * + * **Example** (Embedding custom input handling) + * + * ```ts + * import { Channel, Effect } from "effect" * * // Create a base channel * const baseChannel = Channel.fromIterable([1, 2, 3]) * - * // Embed input handling - simplified example + * // Drain the embedded input while the base channel runs * const embeddedChannel = Channel.embedInput( * baseChannel, - * (_upstream) => Effect.void + * (upstream) => + * upstream.pipe( + * Effect.tap((message) => + * Effect.sync(() => console.log(message)) + * ), + * Effect.forever, + * Effect.ignore + * ) * ) * ``` * + * @category sequencing * @since 2.0.0 - * @category utils */ (input: (upstream: Pull.Pull) => Effect.Effect): (self: Channel) => Channel; /** - * Returns a new channel which embeds the given input handler into a Channel. + * Runs an input handler against the upstream pull while the wrapped channel + * runs without receiving upstream input directly. * - * @example - * ```ts - * import { Channel, Data, Effect } from "effect" + * **Details** * - * class EmbedError extends Data.TaggedError("EmbedError")<{ - * readonly stage: string - * }> {} + * The input handler is forked in the channel scope. The wrapped channel is run + * with an already-completed input. * - * // Create a base channel - * const baseChannel = Channel.fromIterable([1, 2, 3]) + * **Example** (Embedding custom input handling) * - * // Embed input handling - simplified example - * const embeddedChannel = Channel.embedInput( + * ```ts + * import { Channel, Effect } from "effect" + * + * // Create a base channel + * const baseChannel = Channel.fromIterable([1, 2, 3]) + * + * // Drain the embedded input while the base channel runs + * const embeddedChannel = Channel.embedInput( * baseChannel, - * (_upstream) => Effect.void + * (upstream) => + * upstream.pipe( + * Effect.tap((message) => + * Effect.sync(() => console.log(message)) + * ), + * Effect.forever, + * Effect.ignore + * ) * ) * ``` * + * @category sequencing * @since 2.0.0 - * @category utils */ (self: Channel, input: (upstream: Pull.Pull) => Effect.Effect): Channel; }; /** - * Allows a faster producer to progress independently of a slower consumer by - * buffering up to `capacity` elements in a queue. + * Buffers individual output elements in a queue with the configured `capacity` + * so a faster producer can progress independently of a slower consumer. + * + * **When to use** + * + * Use when output elements can be decoupled from downstream demand and the + * configured backpressure or loss strategy is acceptable. + * + * **Details** + * + * Finite queues use the `strategy` option. The default `"suspend"` strategy + * applies backpressure, while `"dropping"` and `"sliding"` can discard output + * elements when the queue is full. `"unbounded"` capacity does not use a finite + * capacity strategy. + * + * **Gotchas** + * + * Dropping and sliding strategies can lose output elements under backpressure. + * + * @see {@link bufferArray} for buffering elements from array outputs * - * @since 2.0.0 * @category Buffering + * @since 2.0.0 */ export declare const buffer: { /** - * Allows a faster producer to progress independently of a slower consumer by - * buffering up to `capacity` elements in a queue. + * Buffers individual output elements in a queue with the configured `capacity` + * so a faster producer can progress independently of a slower consumer. + * + * **When to use** + * + * Use when output elements can be decoupled from downstream demand and the + * configured backpressure or loss strategy is acceptable. + * + * **Details** + * + * Finite queues use the `strategy` option. The default `"suspend"` strategy + * applies backpressure, while `"dropping"` and `"sliding"` can discard output + * elements when the queue is full. `"unbounded"` capacity does not use a finite + * capacity strategy. + * + * **Gotchas** + * + * Dropping and sliding strategies can lose output elements under backpressure. + * + * @see {@link bufferArray} for buffering elements from array outputs * - * @since 2.0.0 * @category Buffering + * @since 2.0.0 */ (options: { readonly capacity: "unbounded"; @@ -4263,11 +5338,29 @@ export declare const buffer: { readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; }): (self: Channel) => Channel; /** - * Allows a faster producer to progress independently of a slower consumer by - * buffering up to `capacity` elements in a queue. + * Buffers individual output elements in a queue with the configured `capacity` + * so a faster producer can progress independently of a slower consumer. + * + * **When to use** + * + * Use when output elements can be decoupled from downstream demand and the + * configured backpressure or loss strategy is acceptable. + * + * **Details** + * + * Finite queues use the `strategy` option. The default `"suspend"` strategy + * applies backpressure, while `"dropping"` and `"sliding"` can discard output + * elements when the queue is full. `"unbounded"` capacity does not use a finite + * capacity strategy. + * + * **Gotchas** + * + * Dropping and sliding strategies can lose output elements under backpressure. + * + * @see {@link bufferArray} for buffering elements from array outputs * - * @since 2.0.0 * @category Buffering + * @since 2.0.0 */ (self: Channel, options: { readonly capacity: "unbounded"; @@ -4277,19 +5370,59 @@ export declare const buffer: { }): Channel; }; /** - * Allows a faster producer to progress independently of a slower consumer by - * buffering up to `capacity` elements in a queue. + * Buffers array output elements in a queue with the configured `capacity` so a + * faster producer can progress independently of a slower consumer. + * + * **When to use** + * + * Use when emitted arrays are batches of elements and it is acceptable for + * buffering to flatten and rebuild those batches. + * + * **Details** + * + * Finite queues use the `strategy` option. The default `"suspend"` strategy + * applies backpressure, while `"dropping"` and `"sliding"` can discard output + * elements when the queue is full. `"unbounded"` capacity does not use a finite + * capacity strategy. + * + * **Gotchas** + * + * Input arrays are offered to the queue element-by-element and outputs are + * rebuilt from the currently available queued elements, so upstream array + * boundaries are not preserved. + * + * @see {@link buffer} for buffering output elements without flattening arrays * - * @since 2.0.0 * @category Buffering + * @since 4.0.0 */ export declare const bufferArray: { /** - * Allows a faster producer to progress independently of a slower consumer by - * buffering up to `capacity` elements in a queue. + * Buffers array output elements in a queue with the configured `capacity` so a + * faster producer can progress independently of a slower consumer. + * + * **When to use** + * + * Use when emitted arrays are batches of elements and it is acceptable for + * buffering to flatten and rebuild those batches. + * + * **Details** + * + * Finite queues use the `strategy` option. The default `"suspend"` strategy + * applies backpressure, while `"dropping"` and `"sliding"` can discard output + * elements when the queue is full. `"unbounded"` capacity does not use a finite + * capacity strategy. + * + * **Gotchas** + * + * Input arrays are offered to the queue element-by-element and outputs are + * rebuilt from the currently available queued elements, so upstream array + * boundaries are not preserved. + * + * @see {@link buffer} for buffering output elements without flattening arrays * - * @since 2.0.0 * @category Buffering + * @since 4.0.0 */ (options: { readonly capacity: "unbounded"; @@ -4298,11 +5431,31 @@ export declare const bufferArray: { readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; }): (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>) => Channel, OutErr, OutDone, InElem, InErr, InDone, Env>; /** - * Allows a faster producer to progress independently of a slower consumer by - * buffering up to `capacity` elements in a queue. + * Buffers array output elements in a queue with the configured `capacity` so a + * faster producer can progress independently of a slower consumer. + * + * **When to use** + * + * Use when emitted arrays are batches of elements and it is acceptable for + * buffering to flatten and rebuild those batches. + * + * **Details** + * + * Finite queues use the `strategy` option. The default `"suspend"` strategy + * applies backpressure, while `"dropping"` and `"sliding"` can discard output + * elements when the queue is full. `"unbounded"` capacity does not use a finite + * capacity strategy. + * + * **Gotchas** + * + * Input arrays are offered to the queue element-by-element and outputs are + * rebuilt from the currently available queued elements, so upstream array + * boundaries are not preserved. + * + * @see {@link buffer} for buffering output elements without flattening arrays * - * @since 2.0.0 * @category Buffering + * @since 4.0.0 */ (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>, options: { readonly capacity: "unbounded"; @@ -4312,83 +5465,146 @@ export declare const bufferArray: { }): Channel, OutErr, OutDone, InElem, InErr, InDone, Env>; }; /** - * Returns a new channel, which is the same as this one, except it will be - * interrupted when the specified effect completes. If the effect completes - * successfully before the underlying channel is done, then the returned - * channel will yield the success value of the effect as its terminal value. - * On the other hand, if the underlying channel finishes first, then the - * returned channel will yield the success value of the underlying channel as - * its terminal value. + * Interrupts a channel when another effect completes. + * + * **When to use** + * + * Use to race channel execution against an external effect whose success can + * become the channel's done value. + * + * **Details** * + * If the effect completes first, its success value becomes the returned + * channel's done value. If the channel completes first, the original channel's + * done value is preserved. + * + * @category interruption * @since 2.0.0 - * @category utils */ export declare const interruptWhen: { /** - * Returns a new channel, which is the same as this one, except it will be - * interrupted when the specified effect completes. If the effect completes - * successfully before the underlying channel is done, then the returned - * channel will yield the success value of the effect as its terminal value. - * On the other hand, if the underlying channel finishes first, then the - * returned channel will yield the success value of the underlying channel as - * its terminal value. + * Interrupts a channel when another effect completes. + * + * **When to use** + * + * Use to race channel execution against an external effect whose success can + * become the channel's done value. + * + * **Details** * + * If the effect completes first, its success value becomes the returned + * channel's done value. If the channel completes first, the original channel's + * done value is preserved. + * + * @category interruption * @since 2.0.0 - * @category utils */ (effect: Effect.Effect): (self: Channel) => Channel; /** - * Returns a new channel, which is the same as this one, except it will be - * interrupted when the specified effect completes. If the effect completes - * successfully before the underlying channel is done, then the returned - * channel will yield the success value of the effect as its terminal value. - * On the other hand, if the underlying channel finishes first, then the - * returned channel will yield the success value of the underlying channel as - * its terminal value. + * Interrupts a channel when another effect completes. + * + * **When to use** + * + * Use to race channel execution against an external effect whose success can + * become the channel's done value. * + * **Details** + * + * If the effect completes first, its success value becomes the returned + * channel's done value. If the channel completes first, the original channel's + * done value is preserved. + * + * @category interruption * @since 2.0.0 - * @category utils */ (self: Channel, effect: Effect.Effect): Channel; }; /** + * Stops a channel when the specified effect completes or fails. + * + * **Details** + * + * If the effect completes before the channel is done, its success value becomes + * the returned channel's done value. If the effect fails, the returned channel + * fails with that error. If the channel completes first, the channel's done + * value is preserved. + * + * @category interruption * @since 4.0.0 - * @category utils */ export declare const haltWhen: { /** + * Stops a channel when the specified effect completes or fails. + * + * **Details** + * + * If the effect completes before the channel is done, its success value becomes + * the returned channel's done value. If the effect fails, the returned channel + * fails with that error. If the channel completes first, the channel's done + * value is preserved. + * + * @category interruption * @since 4.0.0 - * @category utils */ (effect: Effect.Effect): (self: Channel) => Channel; /** + * Stops a channel when the specified effect completes or fails. + * + * **Details** + * + * If the effect completes before the channel is done, its success value becomes + * the returned channel's done value. If the effect fails, the returned channel + * fails with that error. If the channel completes first, the channel's done + * value is preserved. + * + * @category interruption * @since 4.0.0 - * @category utils */ (self: Channel, effect: Effect.Effect): Channel; }; /** + * Attaches a finalizer that runs only when the channel exits with failure. + * + * **Details** + * + * The finalizer receives the failure `Cause`. The original channel failure is + * preserved. The finalizer itself must not fail. + * + * @category error handling * @since 4.0.0 - * @category utils */ export declare const onError: { /** + * Attaches a finalizer that runs only when the channel exits with failure. + * + * **Details** + * + * The finalizer receives the failure `Cause`. The original channel failure is + * preserved. The finalizer itself must not fail. + * + * @category error handling * @since 4.0.0 - * @category utils */ (finalizer: (cause: Cause.Cause) => Effect.Effect): (self: Channel) => Channel; /** + * Attaches a finalizer that runs only when the channel exits with failure. + * + * **Details** + * + * The finalizer receives the failure `Cause`. The original channel failure is + * preserved. The finalizer itself must not fail. + * + * @category error handling * @since 4.0.0 - * @category utils */ (self: Channel, finalizer: (cause: Cause.Cause) => Effect.Effect): Channel; }; /** - * Returns a new channel with an attached finalizer. The finalizer is - * guaranteed to be executed so long as the channel begins execution (and - * regardless of whether or not it completes). + * Returns a channel with an exit-aware finalizer that is guaranteed to run once + * the channel begins execution, whether it succeeds or fails. + * + * **Example** (Running exit finalizers) * - * @example * ```ts * import { Channel, Console, Data, Exit } from "effect" * @@ -4409,16 +5625,16 @@ export declare const onError: { * }) * ``` * + * @category resource management * @since 4.0.0 - * @category utils */ export declare const onExit: { /** - * Returns a new channel with an attached finalizer. The finalizer is - * guaranteed to be executed so long as the channel begins execution (and - * regardless of whether or not it completes). + * Returns a channel with an exit-aware finalizer that is guaranteed to run once + * the channel begins execution, whether it succeeds or fails. + * + * **Example** (Running exit finalizers) * - * @example * ```ts * import { Channel, Console, Data, Exit } from "effect" * @@ -4439,16 +5655,16 @@ export declare const onExit: { * }) * ``` * + * @category resource management * @since 4.0.0 - * @category utils */ (finalizer: (e: Exit.Exit) => Effect.Effect): (self: Channel) => Channel; /** - * Returns a new channel with an attached finalizer. The finalizer is - * guaranteed to be executed so long as the channel begins execution (and - * regardless of whether or not it completes). + * Returns a channel with an exit-aware finalizer that is guaranteed to run once + * the channel begins execution, whether it succeeds or fails. + * + * **Example** (Running exit finalizers) * - * @example * ```ts * import { Channel, Console, Data, Exit } from "effect" * @@ -4469,65 +5685,149 @@ export declare const onExit: { * }) * ``` * + * @category resource management * @since 4.0.0 - * @category utils */ (self: Channel, finalizer: (e: Exit.Exit) => Effect.Effect): Channel; }; /** + * Runs an effect before the channel starts. + * + * **Details** + * + * The effect's successful value is ignored. If the effect fails, the returned + * channel fails before running the source channel. + * + * @category hooks * @since 4.0.0 - * @category utils */ export declare const onStart: { /** + * Runs an effect before the channel starts. + * + * **Details** + * + * The effect's successful value is ignored. If the effect fails, the returned + * channel fails before running the source channel. + * + * @category hooks * @since 4.0.0 - * @category utils */ (onStart: Effect.Effect): (self: Channel) => Channel; /** + * Runs an effect before the channel starts. + * + * **Details** + * + * The effect's successful value is ignored. If the effect fails, the returned + * channel fails before running the source channel. + * + * @category hooks * @since 4.0.0 - * @category utils */ (self: Channel, onStart: Effect.Effect): Channel; }; /** + * Runs an effect the first time the channel emits an output element. + * + * **When to use** + * + * Use when initialization depends on the first output element rather than only + * on channel startup. + * + * **Details** + * + * The effect receives the first emitted element. The first element is still + * emitted unchanged. The effect is not run if the channel completes without + * emitting an element. + * + * @category hooks * @since 4.0.0 - * @category utils */ export declare const onFirst: { /** + * Runs an effect the first time the channel emits an output element. + * + * **When to use** + * + * Use when initialization depends on the first output element rather than only + * on channel startup. + * + * **Details** + * + * The effect receives the first emitted element. The first element is still + * emitted unchanged. The effect is not run if the channel completes without + * emitting an element. + * + * @category hooks * @since 4.0.0 - * @category utils */ (onFirst: (element: Types.NoInfer) => Effect.Effect): (self: Channel) => Channel; /** + * Runs an effect the first time the channel emits an output element. + * + * **When to use** + * + * Use when initialization depends on the first output element rather than only + * on channel startup. + * + * **Details** + * + * The effect receives the first emitted element. The first element is still + * emitted unchanged. The effect is not run if the channel completes without + * emitting an element. + * + * @category hooks * @since 4.0.0 - * @category utils */ (self: Channel, onFirst: (element: Types.NoInfer) => Effect.Effect): Channel; }; /** + * Runs an effect when the channel completes successfully. + * + * **Details** + * + * The effect runs before the original done value is propagated. The effect is + * not run when the channel fails. If the effect fails, the returned channel + * fails with that error. + * + * @category hooks * @since 4.0.0 - * @category utils */ export declare const onEnd: { /** + * Runs an effect when the channel completes successfully. + * + * **Details** + * + * The effect runs before the original done value is propagated. The effect is + * not run when the channel fails. If the effect fails, the returned channel + * fails with that error. + * + * @category hooks * @since 4.0.0 - * @category utils */ (onEnd: Effect.Effect): (self: Channel) => Channel; /** + * Runs an effect when the channel completes successfully. + * + * **Details** + * + * The effect runs before the original done value is propagated. The effect is + * not run when the channel fails. If the effect fails, the returned channel + * fails with that error. + * + * @category hooks * @since 4.0.0 - * @category utils */ (self: Channel, onEnd: Effect.Effect): Channel; }; /** - * Returns a new channel with an attached finalizer. The finalizer is - * guaranteed to be executed so long as the channel begins execution (and - * regardless of whether or not it completes). + * Returns a channel with a finalizer effect that is guaranteed to run once the + * channel begins execution, whether it succeeds or fails. + * + * **Example** (Ensuring cleanup runs) * - * @example * ```ts * import { Channel, Console, Data } from "effect" * @@ -4545,16 +5845,16 @@ export declare const onEnd: { * ) * ``` * + * @category resource management * @since 2.0.0 - * @category utils */ export declare const ensuring: { /** - * Returns a new channel with an attached finalizer. The finalizer is - * guaranteed to be executed so long as the channel begins execution (and - * regardless of whether or not it completes). + * Returns a channel with a finalizer effect that is guaranteed to run once the + * channel begins execution, whether it succeeds or fails. + * + * **Example** (Ensuring cleanup runs) * - * @example * ```ts * import { Channel, Console, Data } from "effect" * @@ -4572,16 +5872,16 @@ export declare const ensuring: { * ) * ``` * + * @category resource management * @since 2.0.0 - * @category utils */ (finalizer: Effect.Effect): (self: Channel) => Channel; /** - * Returns a new channel with an attached finalizer. The finalizer is - * guaranteed to be executed so long as the channel begins execution (and - * regardless of whether or not it completes). + * Returns a channel with a finalizer effect that is guaranteed to run once the + * channel begins execution, whether it succeeds or fails. + * + * **Example** (Ensuring cleanup runs) * - * @example * ```ts * import { Channel, Console, Data } from "effect" * @@ -4599,149 +5899,286 @@ export declare const ensuring: { * ) * ``` * + * @category resource management * @since 2.0.0 - * @category utils */ (self: Channel, finalizer: Effect.Effect): Channel; }; /** - * Create a channel from the specified services. + * Creates a channel from the specified services. * + * @category services * @since 2.0.0 - * @category Services */ export declare const contextWith: (f: (context: Context.Context) => Channel) => Channel; /** - * Provides a layer or context to the channel, removing the corresponding - * service requirements. Use `options.local` to build the layer every time; by - * default, layers are shared between provide calls. + * Provides a `Context` to the channel, removing the corresponding service + * requirements from the returned channel. * - * @since 4.0.0 - * @category Services + * @category services + * @since 2.0.0 */ export declare const provideContext: { /** - * Provides a layer or context to the channel, removing the corresponding - * service requirements. Use `options.local` to build the layer every time; by - * default, layers are shared between provide calls. + * Provides a `Context` to the channel, removing the corresponding service + * requirements from the returned channel. * - * @since 4.0.0 - * @category Services + * @category services + * @since 2.0.0 */ (context: Context.Context): (self: Channel) => Channel>; /** - * Provides a layer or context to the channel, removing the corresponding - * service requirements. Use `options.local` to build the layer every time; by - * default, layers are shared between provide calls. + * Provides a `Context` to the channel, removing the corresponding service + * requirements from the returned channel. * - * @since 4.0.0 - * @category Services + * @category services + * @since 2.0.0 */ (self: Channel, context: Context.Context): Channel>; }; /** - * @since 4.0.0 - * @category Services + * Provides a concrete service for a context key, removing that service + * requirement from the returned channel. + * + * @category services + * @since 2.0.0 */ export declare const provideService: { /** - * @since 4.0.0 - * @category Services + * Provides a concrete service for a context key, removing that service + * requirement from the returned channel. + * + * @category services + * @since 2.0.0 */ (key: Context.Key, service: NoInfer): (self: Channel) => Channel>; /** - * @since 4.0.0 - * @category Services + * Provides a concrete service for a context key, removing that service + * requirement from the returned channel. + * + * @category services + * @since 2.0.0 */ (self: Channel, key: Context.Key, service: NoInfer): Channel>; }; /** + * Provides a service to the channel after obtaining it from an effect. + * + * **When to use** + * + * Use to supply a channel dependency when constructing the service itself is + * effectful or can fail. + * + * **Details** + * + * If the service effect fails, the returned channel fails. The provided service + * removes the corresponding service requirement from the returned channel. + * + * @category services * @since 4.0.0 - * @category Services */ export declare const provideServiceEffect: { /** + * Provides a service to the channel after obtaining it from an effect. + * + * **When to use** + * + * Use to supply a channel dependency when constructing the service itself is + * effectful or can fail. + * + * **Details** + * + * If the service effect fails, the returned channel fails. The provided service + * removes the corresponding service requirement from the returned channel. + * + * @category services * @since 4.0.0 - * @category Services */ (key: Context.Key, service: Effect.Effect, ES, RS>): (self: Channel) => Channel | RS>; /** + * Provides a service to the channel after obtaining it from an effect. + * + * **When to use** + * + * Use to supply a channel dependency when constructing the service itself is + * effectful or can fail. + * + * **Details** + * + * If the service effect fails, the returned channel fails. The provided service + * removes the corresponding service requirement from the returned channel. + * + * @category services * @since 4.0.0 - * @category Services */ (self: Channel, key: Context.Key, service: Effect.Effect, ES, RS>): Channel | RS>; }; /** + * Provides a `Layer` or `Context` to the channel, removing the corresponding + * service requirements. + * + * **Details** + * + * Providing a `Context` delegates to `provideContext`. Providing a `Layer` + * builds the layer in the channel scope. Use `options.local` to build a fresh + * layer instance for this provision. + * + * @category services * @since 4.0.0 - * @category Services */ export declare const provide: { /** + * Provides a `Layer` or `Context` to the channel, removing the corresponding + * service requirements. + * + * **Details** + * + * Providing a `Context` delegates to `provideContext`. Providing a `Layer` + * builds the layer in the channel scope. Use `options.local` to build a fresh + * layer instance for this provision. + * + * @category services * @since 4.0.0 - * @category Services */ (layer: Layer.Layer | Context.Context, options?: { readonly local?: boolean | undefined; } | undefined): (self: Channel) => Channel | R>; /** + * Provides a `Layer` or `Context` to the channel, removing the corresponding + * service requirements. + * + * **Details** + * + * Providing a `Context` delegates to `provideContext`. Providing a `Layer` + * builds the layer in the channel scope. Use `options.local` to build a fresh + * layer instance for this provision. + * + * @category services * @since 4.0.0 - * @category Services */ (self: Channel, layer: Layer.Layer | Context.Context, options?: { readonly local?: boolean | undefined; } | undefined): Channel | R>; }; /** - * @since 2.0.0 - * @category Services + * Transforms the current context before running the channel. + * + * **Details** + * + * The function receives the surrounding context and returns the context to + * provide to the channel. The returned channel requires the services needed to + * build that context. + * + * @category services + * @since 4.0.0 */ export declare const updateContext: { /** - * @since 2.0.0 - * @category Services + * Transforms the current context before running the channel. + * + * **Details** + * + * The function receives the surrounding context and returns the context to + * provide to the channel. The returned channel requires the services needed to + * build that context. + * + * @category services + * @since 4.0.0 */ (f: (context: Context.Context) => Context.Context): (self: Channel) => Channel; /** - * @since 2.0.0 - * @category Services + * Transforms the current context before running the channel. + * + * **Details** + * + * The function receives the surrounding context and returns the context to + * provide to the channel. The returned channel requires the services needed to + * build that context. + * + * @category services + * @since 4.0.0 */ (self: Channel, f: (context: Context.Context) => Context.Context): Channel; }; /** + * Updates a service in the current context before running the channel. + * + * **Details** + * + * The existing service is read from the context. The updated service is + * provided to the channel under the same key. + * + * @category services * @since 2.0.0 - * @category Services */ export declare const updateService: { /** + * Updates a service in the current context before running the channel. + * + * **Details** + * + * The existing service is read from the context. The updated service is + * provided to the channel under the same key. + * + * @category services * @since 2.0.0 - * @category Services */ (key: Context.Key, f: (service: NoInfer) => S): (self: Channel) => Channel; /** + * Updates a service in the current context before running the channel. + * + * **Details** + * + * The existing service is read from the context. The updated service is + * provided to the channel under the same key. + * + * @category services * @since 2.0.0 - * @category Services */ (self: Channel, service: Context.Key, f: (service: NoInfer) => S): Channel; }; /** - * @since 4.0.0 - * @category Tracing + * Runs the channel inside a tracing span with the specified name and options. + * + * **Details** + * + * The created span is provided as the current parent span while the channel + * runs. The span is ended with the channel's exit value. + * + * @category tracing + * @since 2.0.0 */ export declare const withSpan: { /** - * @since 4.0.0 - * @category Tracing + * Runs the channel inside a tracing span with the specified name and options. + * + * **Details** + * + * The created span is provided as the current parent span while the channel + * runs. The span is ended with the channel's exit value. + * + * @category tracing + * @since 2.0.0 */ (name: string, options?: SpanOptions): (self: Channel) => Channel>; /** - * @since 4.0.0 - * @category Tracing + * Runs the channel inside a tracing span with the specified name and options. + * + * **Details** + * + * The created span is provided as the current parent span while the channel + * runs. The span is ended with the channel's exit value. + * + * @category tracing + * @since 2.0.0 */ (self: Channel, name: string, options?: SpanOptions): Channel>; }; /** + * The starting channel for Do notation, emitting an empty object. + * + * @category do notation * @since 4.0.0 - * @category Do notation */ export declare const Do: Channel<{}>; declare const let_: { @@ -4754,18 +6191,38 @@ declare const let_: { }; export { /** + * Adds a computed field to each object emitted by a channel. + * + * @category do notation * @since 4.0.0 - * @category Do notation */ let_ as let }; /** + * Adds a field to each object emitted by a channel by running another channel + * derived from that object. + * + * **Details** + * + * The field name must not already exist on the emitted object. The derived + * channel's output becomes the value of the new field. `options.concurrency` + * and `options.bufferSize` control how derived channels are flattened. + * + * @category do notation * @since 4.0.0 - * @category Do notation */ export declare const bind: { /** + * Adds a field to each object emitted by a channel by running another channel + * derived from that object. + * + * **Details** + * + * The field name must not already exist on the emitted object. The derived + * channel's output becomes the value of the new field. `options.concurrency` + * and `options.bufferSize` control how derived channels are flattened. + * + * @category do notation * @since 4.0.0 - * @category Do notation */ (name: Exclude, f: (a: NoInfer) => Channel, options?: { readonly concurrency?: number | "unbounded" | undefined; @@ -4774,8 +6231,17 @@ export declare const bind: { [K in N | keyof OutElem]: K extends keyof OutElem ? OutElem[K] : B; }, OutErr2 | OutErr, OutDone, InElem & InElem2, InErr & InErr2, InDone & InDone2, Env2 | Env>; /** + * Adds a field to each object emitted by a channel by running another channel + * derived from that object. + * + * **Details** + * + * The field name must not already exist on the emitted object. The derived + * channel's output becomes the value of the new field. `options.concurrency` + * and `options.bufferSize` control how derived channels are flattened. + * + * @category do notation * @since 4.0.0 - * @category Do notation */ (self: Channel, name: Exclude, f: (a: NoInfer) => Channel, options?: { readonly concurrency?: number | "unbounded" | undefined; @@ -4785,20 +6251,53 @@ export declare const bind: { }, OutErr2 | OutErr, OutDone, InElem & InElem2, InErr & InErr2, InDone & InDone2, Env2 | Env>; }; /** + * Wraps each output element in an object under the specified field name. + * + * **When to use** + * + * Use when you need to start a Channel Do-notation chain from an existing + * output value by assigning that value to a field name. + * + * @see {@link Do} for starting Do notation from an empty object + * @see {@link bind} for adding a field produced by another channel + * @see {@link let_ let} for adding a computed field + * + * @category do notation * @since 4.0.0 - * @category Do notation */ export declare const bindTo: { /** + * Wraps each output element in an object under the specified field name. + * + * **When to use** + * + * Use when you need to start a Channel Do-notation chain from an existing + * output value by assigning that value to a field name. + * + * @see {@link Do} for starting Do notation from an empty object + * @see {@link bind} for adding a field produced by another channel + * @see {@link let_ let} for adding a computed field + * + * @category do notation * @since 4.0.0 - * @category Do notation */ (name: N): (self: Channel) => Channel<{ [K in N]: OutElem; }, OutErr, OutDone, InElem, InErr, InDone, Env>; /** + * Wraps each output element in an object under the specified field name. + * + * **When to use** + * + * Use when you need to start a Channel Do-notation chain from an existing + * output value by assigning that value to a field name. + * + * @see {@link Do} for starting Do notation from an empty object + * @see {@link bind} for adding a field produced by another channel + * @see {@link let_ let} for adding a computed field + * + * @category do notation * @since 4.0.0 - * @category Do notation */ (self: Channel, name: N): Channel<{ [K in N]: OutElem; @@ -4807,7 +6306,8 @@ export declare const bindTo: { /** * Runs a channel and counts the number of elements it outputs. * - * @example + * **Example** (Counting channel output) + * * ```ts * import { Channel, Data } from "effect" * @@ -4824,14 +6324,15 @@ export declare const bindTo: { * // Effect.runSync(countEffect) // Returns: 5 * ``` * - * @since 2.0.0 * @category execution + * @since 4.0.0 */ export declare const runCount: (self: Channel) => Effect.Effect; /** * Runs a channel and discards all output elements, returning only the final result. * - * @example + * **Example** (Draining channel output at runtime) + * * ```ts * import { Channel, Data } from "effect" * @@ -4852,14 +6353,15 @@ export declare const runCount: (self: Channel(self: Channel) => Effect.Effect; /** * Runs a channel and applies an effect to each output element. * - * @example + * **Example** (Running effects for each output) + * * ```ts * import { Channel, Console, Data } from "effect" * @@ -4879,14 +6381,15 @@ export declare const runDrain: (self: Channel(f: (o: OutElem) => Effect.Effect): (self: Channel) => Effect.Effect; /** * Runs a channel and applies an effect to each output element. * - * @example + * **Example** (Running effects for each output) + * * ```ts * import { Channel, Console, Data } from "effect" * @@ -4933,31 +6437,56 @@ export declare const runForEach: { * // Logs: "Processing: 1", "Processing: 2", "Processing: 3" * ``` * - * @since 2.0.0 * @category execution + * @since 4.0.0 */ (self: Channel, f: (o: OutElem) => Effect.Effect): Effect.Effect; }; /** - * @since 2.0.0 + * Runs a channel and applies an effectful predicate to each output element + * until the predicate returns `false`. + * + * **Details** + * + * Returning `true` continues consuming the channel. Returning `false` stops + * consumption early. The returned effect completes with `void`. + * * @category execution + * @since 4.0.0 */ export declare const runForEachWhile: { /** - * @since 2.0.0 + * Runs a channel and applies an effectful predicate to each output element + * until the predicate returns `false`. + * + * **Details** + * + * Returning `true` continues consuming the channel. Returning `false` stops + * consumption early. The returned effect completes with `void`. + * * @category execution + * @since 4.0.0 */ (f: (o: OutElem) => Effect.Effect): (self: Channel) => Effect.Effect; /** - * @since 2.0.0 + * Runs a channel and applies an effectful predicate to each output element + * until the predicate returns `false`. + * + * **Details** + * + * Returning `true` continues consuming the channel. Returning `false` stops + * consumption early. The returned effect completes with `void`. + * * @category execution + * @since 4.0.0 */ (self: Channel, f: (o: OutElem) => Effect.Effect): Effect.Effect; }; /** * Runs a channel and collects all output elements into an array. * - * @example + * **Example** (Collecting channel output) + * * ```ts * import { Channel, Data } from "effect" * @@ -4974,31 +6503,48 @@ export declare const runForEachWhile: { * // Effect.runSync(collectEffect) // Returns: [1, 2, 3, 4, 5] * ``` * - * @since 2.0.0 * @category execution + * @since 2.0.0 */ export declare const runCollect: (self: Channel) => Effect.Effect, OutErr, Env>; /** * Runs a channel and outputs the done value. * - * @since 4.0.0 * @category execution + * @since 4.0.0 */ export declare const runDone: (self: Channel) => Effect.Effect; /** - * @since 2.0.0 + * Runs a channel until the first output element is available, returning it in + * an `Option`. + * + * **Details** + * + * Returns `Option.some` with the first output element, or `Option.none` if the + * channel completes without emitting output. + * * @category execution + * @since 4.0.0 */ export declare const runHead: (self: Channel) => Effect.Effect, OutErr, Env>; /** - * @since 2.0.0 + * Runs a channel to completion and returns the last output element in an + * `Option`. + * + * **Details** + * + * Returns `Option.some` with the last emitted element, or `Option.none` if the + * channel completes without emitting output. + * * @category execution + * @since 4.0.0 */ export declare const runLast: (self: Channel) => Effect.Effect, OutErr, Env>; /** * Runs a channel and folds over all output elements with an accumulator. * - * @example + * **Example** (Folding channel output) + * * ```ts * import { Channel, Data } from "effect" * @@ -5015,14 +6561,15 @@ export declare const runLast: (self: Channel(initial: LazyArg, f: (acc: Z, o: OutElem) => Z): (self: Channel) => Effect.Effect; /** * Runs a channel and folds over all output elements with an accumulator. * - * @example + * **Example** (Folding channel output) + * * ```ts * import { Channel, Data } from "effect" * @@ -5063,31 +6611,77 @@ export declare const runFold: { * // Effect.runSync(sumEffect) // Returns: 15 * ``` * - * @since 2.0.0 * @category execution + * @since 4.0.0 */ (self: Channel, initial: LazyArg, f: (acc: Z, o: OutElem) => Z): Effect.Effect; }; /** - * @since 2.0.0 + * Runs a channel and effectfully folds all output elements with an accumulator. + * + * **When to use** + * + * Use when folding channel output needs effects, services, or an additional + * failure channel during accumulation. + * + * **Details** + * + * The initial accumulator is evaluated lazily. Each output element is passed to + * the effectful accumulator function. The returned effect succeeds with the + * final accumulator value. + * * @category execution + * @since 4.0.0 */ export declare const runFoldEffect: { /** - * @since 2.0.0 + * Runs a channel and effectfully folds all output elements with an accumulator. + * + * **When to use** + * + * Use when folding channel output needs effects, services, or an additional + * failure channel during accumulation. + * + * **Details** + * + * The initial accumulator is evaluated lazily. Each output element is passed to + * the effectful accumulator function. The returned effect succeeds with the + * final accumulator value. + * * @category execution + * @since 4.0.0 */ (initial: LazyArg, f: (acc: Z, o: OutElem) => Effect.Effect): (self: Channel) => Effect.Effect; /** - * @since 2.0.0 + * Runs a channel and effectfully folds all output elements with an accumulator. + * + * **When to use** + * + * Use when folding channel output needs effects, services, or an additional + * failure channel during accumulation. + * + * **Details** + * + * The initial accumulator is evaluated lazily. Each output element is passed to + * the effectful accumulator function. The returned effect succeeds with the + * final accumulator value. + * * @category execution + * @since 4.0.0 */ (self: Channel, initial: LazyArg, f: (acc: Z, o: OutElem) => Effect.Effect): Effect.Effect; }; /** - * Converts a channel to a Pull data structure for low-level consumption. + * Converts a channel to a scoped `Pull` for low-level consumption. + * + * **Details** + * + * The effect requires a `Scope`. The returned pull should be consumed only + * while that scope remains open. Pulls are serialized so only one pull is + * evaluated at a time. + * + * **Example** (Converting channels to pulls) * - * @example * ```ts * import { Channel, Data, Effect } from "effect" * @@ -5106,14 +6700,15 @@ export declare const runFoldEffect: { * // Use the Pull to manually consume elements * ``` * + * @category destructors * @since 2.0.0 - * @category Destructors */ export declare const toPull: (self: Channel) => Effect.Effect, never, Env | Scope.Scope>; /** * Converts a channel to a Pull within an existing scope. * - * @example + * **Example** (Converting channels to scoped pulls) + * * ```ts * import { Channel, Data, Effect, Scope } from "effect" * @@ -5132,46 +6727,105 @@ export declare const toPull: (self: Channel(self: Channel, scope: Scope.Scope) => Effect.Effect, never, Env>; /** + * Runs a channel and offers each output element into a queue. + * + * **Details** + * + * When the channel completes, the queue is ended. When the channel fails, the + * queue is failed with the channel's cause. The returned effect itself + * completes with `void`. + * + * @category destructors * @since 4.0.0 - * @category Destructors */ export declare const runIntoQueue: { /** + * Runs a channel and offers each output element into a queue. + * + * **Details** + * + * When the channel completes, the queue is ended. When the channel fails, the + * queue is failed with the channel's cause. The returned effect itself + * completes with `void`. + * + * @category destructors * @since 4.0.0 - * @category Destructors */ (queue: Queue.Queue): (self: Channel) => Effect.Effect; /** + * Runs a channel and offers each output element into a queue. + * + * **Details** + * + * When the channel completes, the queue is ended. When the channel fails, the + * queue is failed with the channel's cause. The returned effect itself + * completes with `void`. + * + * @category destructors * @since 4.0.0 - * @category Destructors */ (self: Channel, queue: Queue.Queue): Effect.Effect; }; /** + * Runs a channel that emits non-empty arrays and offers each array element into + * a queue. + * + * **Details** + * + * When the channel completes, the queue is ended. When the channel fails, the + * queue is failed with the channel's cause. The returned effect itself + * completes with `void`. + * + * @category destructors * @since 4.0.0 - * @category Destructors */ export declare const runIntoQueueArray: { /** + * Runs a channel that emits non-empty arrays and offers each array element into + * a queue. + * + * **Details** + * + * When the channel completes, the queue is ended. When the channel fails, the + * queue is failed with the channel's cause. The returned effect itself + * completes with `void`. + * + * @category destructors * @since 4.0.0 - * @category Destructors */ (queue: Queue.Queue): (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>) => Effect.Effect; /** + * Runs a channel that emits non-empty arrays and offers each array element into + * a queue. + * + * **Details** + * + * When the channel completes, the queue is ended. When the channel fails, the + * queue is failed with the channel's cause. The returned effect itself + * completes with `void`. + * + * @category destructors * @since 4.0.0 - * @category Destructors */ (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>, queue: Queue.Queue): Effect.Effect; }; /** - * Converts a channel to a queue for concurrent consumption. + * Creates a scoped queue and forks the channel to feed it for concurrent + * consumption. + * + * **Details** + * + * Output elements are offered to the queue. Channel completion and failure are + * signaled through the queue. The queue is shut down when the surrounding scope + * closes. + * + * **Example** (Converting channels to queues) * - * @example * ```ts * import { Channel, Data } from "effect" * @@ -5189,14 +6843,22 @@ export declare const runIntoQueueArray: { * // Multiple consumers can read from the queue * ``` * - * @since 4.0.0 - * @category Destructors + * @category destructors + * @since 2.0.0 */ export declare const toQueue: { /** - * Converts a channel to a queue for concurrent consumption. + * Creates a scoped queue and forks the channel to feed it for concurrent + * consumption. + * + * **Details** + * + * Output elements are offered to the queue. Channel completion and failure are + * signaled through the queue. The queue is shut down when the surrounding scope + * closes. + * + * **Example** (Converting channels to queues) * - * @example * ```ts * import { Channel, Data } from "effect" * @@ -5214,8 +6876,8 @@ export declare const toQueue: { * // Multiple consumers can read from the queue * ``` * - * @since 4.0.0 - * @category Destructors + * @category destructors + * @since 2.0.0 */ (options: { readonly capacity: "unbounded"; @@ -5224,9 +6886,17 @@ export declare const toQueue: { readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; }): (self: Channel) => Effect.Effect, never, Env | Scope.Scope>; /** - * Converts a channel to a queue for concurrent consumption. + * Creates a scoped queue and forks the channel to feed it for concurrent + * consumption. + * + * **Details** + * + * Output elements are offered to the queue. Channel completion and failure are + * signaled through the queue. The queue is shut down when the surrounding scope + * closes. + * + * **Example** (Converting channels to queues) * - * @example * ```ts * import { Channel, Data } from "effect" * @@ -5244,8 +6914,8 @@ export declare const toQueue: { * // Multiple consumers can read from the queue * ``` * - * @since 4.0.0 - * @category Destructors + * @category destructors + * @since 2.0.0 */ (self: Channel, options: { readonly capacity: "unbounded"; @@ -5255,13 +6925,29 @@ export declare const toQueue: { }): Effect.Effect, never, Env | Scope.Scope>; }; /** + * Creates a scoped queue and forks an array-emitting channel to feed it. + * + * **Details** + * + * Each element inside emitted non-empty arrays is offered to the queue. Channel + * completion and failure are signaled through the queue. The queue is shut down + * when the surrounding scope closes. + * + * @category destructors * @since 4.0.0 - * @category Destructors */ export declare const toQueueArray: { /** + * Creates a scoped queue and forks an array-emitting channel to feed it. + * + * **Details** + * + * Each element inside emitted non-empty arrays is offered to the queue. Channel + * completion and failure are signaled through the queue. The queue is shut down + * when the surrounding scope closes. + * + * @category destructors * @since 4.0.0 - * @category Destructors */ (options: { readonly capacity: "unbounded"; @@ -5270,8 +6956,16 @@ export declare const toQueueArray: { readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; }): (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>) => Effect.Effect, never, Env | Scope.Scope>; /** + * Creates a scoped queue and forks an array-emitting channel to feed it. + * + * **Details** + * + * Each element inside emitted non-empty arrays is offered to the queue. Channel + * completion and failure are signaled through the queue. The queue is shut down + * when the surrounding scope closes. + * + * @category destructors * @since 4.0.0 - * @category Destructors */ (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>, options: { readonly capacity: "unbounded"; @@ -5283,21 +6977,25 @@ export declare const toQueueArray: { /** * Converts a channel to a PubSub for concurrent consumption. * + * **Details** + * * `shutdownOnEnd` indicates whether the PubSub should be shut down when the * channel ends. By default this is `true`. * - * @since 4.0.0 - * @category Destructors + * @category destructors + * @since 2.0.0 */ export declare const toPubSub: { /** * Converts a channel to a PubSub for concurrent consumption. * + * **Details** + * * `shutdownOnEnd` indicates whether the PubSub should be shut down when the * channel ends. By default this is `true`. * - * @since 4.0.0 - * @category Destructors + * @category destructors + * @since 2.0.0 */ (options: { readonly capacity: "unbounded"; @@ -5312,11 +7010,13 @@ export declare const toPubSub: { /** * Converts a channel to a PubSub for concurrent consumption. * + * **Details** + * * `shutdownOnEnd` indicates whether the PubSub should be shut down when the * channel ends. By default this is `true`. * - * @since 4.0.0 - * @category Destructors + * @category destructors + * @since 2.0.0 */ (self: Channel, options: { readonly capacity: "unbounded"; @@ -5330,43 +7030,72 @@ export declare const toPubSub: { }): Effect.Effect, never, Env | Scope.Scope>; }; /** + * Runs a channel and publishes each output element to a `PubSub`. + * + * **Details** + * + * The channel's output values are published as individual PubSub messages. Use + * `options.shutdownOnEnd` to shut down the PubSub when channel execution ends. + * + * @category destructors * @since 4.0.0 - * @category Destructors */ export declare const runIntoPubSub: { /** + * Runs a channel and publishes each output element to a `PubSub`. + * + * **Details** + * + * The channel's output values are published as individual PubSub messages. Use + * `options.shutdownOnEnd` to shut down the PubSub when channel execution ends. + * + * @category destructors * @since 4.0.0 - * @category Destructors */ (pubsub: PubSub.PubSub, options?: { readonly shutdownOnEnd?: boolean | undefined; } | undefined): (self: Channel) => Effect.Effect; /** + * Runs a channel and publishes each output element to a `PubSub`. + * + * **Details** + * + * The channel's output values are published as individual PubSub messages. Use + * `options.shutdownOnEnd` to shut down the PubSub when channel execution ends. + * + * @category destructors * @since 4.0.0 - * @category Destructors */ (self: Channel, pubsub: PubSub.PubSub, options?: { readonly shutdownOnEnd?: boolean | undefined; } | undefined): Effect.Effect; }; /** - * Converts a channel to a PubSub for concurrent consumption. + * Converts an array-emitting channel to a scoped `PubSub` for concurrent + * consumption. * - * `shutdownOnEnd` indicates whether the PubSub should be shut down when the - * channel ends. By default this is `true`. + * **Details** + * + * Each element inside emitted non-empty arrays is published as an individual + * PubSub message. `shutdownOnEnd` indicates whether the PubSub should be shut + * down when the channel ends. By default this is `true`. * + * @category destructors * @since 4.0.0 - * @category Destructors */ export declare const toPubSubArray: { /** - * Converts a channel to a PubSub for concurrent consumption. + * Converts an array-emitting channel to a scoped `PubSub` for concurrent + * consumption. * - * `shutdownOnEnd` indicates whether the PubSub should be shut down when the - * channel ends. By default this is `true`. + * **Details** * + * Each element inside emitted non-empty arrays is published as an individual + * PubSub message. `shutdownOnEnd` indicates whether the PubSub should be shut + * down when the channel ends. By default this is `true`. + * + * @category destructors * @since 4.0.0 - * @category Destructors */ (options: { readonly capacity: "unbounded"; @@ -5379,13 +7108,17 @@ export declare const toPubSubArray: { readonly shutdownOnEnd?: boolean | undefined; }): (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>) => Effect.Effect, never, Env | Scope.Scope>; /** - * Converts a channel to a PubSub for concurrent consumption. + * Converts an array-emitting channel to a scoped `PubSub` for concurrent + * consumption. * - * `shutdownOnEnd` indicates whether the PubSub should be shut down when the - * channel ends. By default this is `true`. + * **Details** * + * Each element inside emitted non-empty arrays is published as an individual + * PubSub message. `shutdownOnEnd` indicates whether the PubSub should be shut + * down when the channel ends. By default this is `true`. + * + * @category destructors * @since 4.0.0 - * @category Destructors */ (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>, options: { readonly capacity: "unbounded"; @@ -5399,37 +7132,76 @@ export declare const toPubSubArray: { }): Effect.Effect, never, Env | Scope.Scope>; }; /** + * Runs an array-emitting channel and publishes each array element to a + * `PubSub`. + * + * **Details** + * + * Each element inside emitted non-empty arrays is published as an individual + * PubSub message. Use `options.shutdownOnEnd` to shut down the PubSub when + * channel execution ends. + * + * @category destructors * @since 4.0.0 - * @category Destructors */ export declare const runIntoPubSubArray: { /** + * Runs an array-emitting channel and publishes each array element to a + * `PubSub`. + * + * **Details** + * + * Each element inside emitted non-empty arrays is published as an individual + * PubSub message. Use `options.shutdownOnEnd` to shut down the PubSub when + * channel execution ends. + * + * @category destructors * @since 4.0.0 - * @category Destructors */ (pubsub: PubSub.PubSub, options?: { readonly shutdownOnEnd?: boolean | undefined; } | undefined): (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>) => Effect.Effect; /** + * Runs an array-emitting channel and publishes each array element to a + * `PubSub`. + * + * **Details** + * + * Each element inside emitted non-empty arrays is published as an individual + * PubSub message. Use `options.shutdownOnEnd` to shut down the PubSub when + * channel execution ends. + * + * @category destructors * @since 4.0.0 - * @category Destructors */ (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>, pubsub: PubSub.PubSub, options?: { readonly shutdownOnEnd?: boolean | undefined; } | undefined): Effect.Effect; }; /** - * Converts a channel to a PubSub for concurrent consumption. + * Converts a channel to a scoped `PubSub` of `Take` values. * + * **Details** + * + * Emitted non-empty arrays are published as output `Take` values. When the + * channel ends, its final `Exit` is published so subscribers can observe + * completion or failure. + * + * @category destructors * @since 4.0.0 - * @category Destructors */ export declare const toPubSubTake: { /** - * Converts a channel to a PubSub for concurrent consumption. + * Converts a channel to a scoped `PubSub` of `Take` values. + * + * **Details** + * + * Emitted non-empty arrays are published as output `Take` values. When the + * channel ends, its final `Exit` is published so subscribers can observe + * completion or failure. * + * @category destructors * @since 4.0.0 - * @category Destructors */ (options: { readonly capacity: "unbounded"; @@ -5440,10 +7212,16 @@ export declare const toPubSubTake: { readonly replay?: number | undefined; }): (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>) => Effect.Effect>, never, Env | Scope.Scope>; /** - * Converts a channel to a PubSub for concurrent consumption. + * Converts a channel to a scoped `PubSub` of `Take` values. + * + * **Details** + * + * Emitted non-empty arrays are published as output `Take` values. When the + * channel ends, its final `Exit` is published so subscribers can observe + * completion or failure. * + * @category destructors * @since 4.0.0 - * @category Destructors */ (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>, options: { readonly capacity: "unbounded";