diff --git "a/.opencode/node_modules/effect/src/Channel.ts" "b/.opencode/node_modules/effect/src/Channel.ts" --- "a/.opencode/node_modules/effect/src/Channel.ts" +++ "b/.opencode/node_modules/effect/src/Channel.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 */ @@ -93,21 +46,27 @@ 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 const TypeId: TypeId = "~effect/Channel" /** - * Tests if a value is a `Channel`. + * Checks whether a value is a `Channel`. + * + * **Example** (Checking for channels) * - * @example * ```ts * import { Channel } from "effect" * @@ -129,6 +88,8 @@ export const isChannel = ( * `OutElem`. When the channel finishes, it yields a value of type `OutDone`. A * channel may fail with a value of type `OutErr`. * + * **Details** + * * Channels are the foundation of Streams: both streams and sinks are built on * channels. Most users shouldn't have to use channels directly, as streams and * sinks are much more convenient and cover all common use cases. However, when @@ -146,7 +107,8 @@ export const isChannel = ( * channels, which are all concatenated together. The first channel and the * function that makes the other channels can be composed into a channel. * - * @example + * **Example** (Typing channels) + * * ```ts * import type { Channel } from "effect" * @@ -168,8 +130,8 @@ export const isChannel = ( * > * ``` * - * @since 2.0.0 * @category models + * @since 2.0.0 */ export interface Channel< out OutElem, @@ -186,8 +148,16 @@ export interface Channel< } /** - * @since 2.0.0 + * Type-level unification support for `Channel` values. + * + * **Details** + * + * This preserves all `Channel` type parameters when `Unify` normalizes unions + * or generic return types that include channels. Users normally do not need to + * reference this interface directly. + * * @category models + * @since 2.0.0 */ export interface ChannelUnify extends Effect.EffectUnify { Channel?: () => A[Unify.typeSymbol] extends @@ -197,6 +167,15 @@ export interface ChannelUnify extends Ef } /** + * 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 */ @@ -209,8 +188,17 @@ type TagsWithReason = { }[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< out OutElem, @@ -224,8 +212,17 @@ 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< out OutElem, @@ -265,7 +262,8 @@ const ChannelProto = { /** * Creates a `Channel` from a transformation function that operates on upstream pulls. * - * @example + * **Example** (Creating channels from transforms) + * * ```ts * import { Channel, Effect } from "effect" * @@ -300,7 +298,8 @@ export const fromTransform = ( * 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 const fromTransformBracket = ( f: ( @@ -401,7 +408,8 @@ export const fromTransformBracket = ( /** * Creates a `Channel` that interacts with a callback function using a queue. * - * @example + * **Example** (Creating channels from callbacks) + * * ```ts * import { Channel, Effect, Queue } from "effect" * @@ -468,7 +478,7 @@ const asyncQueue = ( * ``` * * @category constructors - * @since 2.0.0 + * @since 4.0.0 */ export const callback = ( f: (queue: Queue.Queue) => Effect.Effect, @@ -482,7 +492,8 @@ export const callback = ( /** * 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" * @@ -508,7 +519,8 @@ export const callbackArray = ( /** * Creates a `Channel` that lazily evaluates to another channel. * - * @example + * **Example** (Suspending channel creation) + * * ```ts * import { Channel } from "effect" * @@ -525,9 +537,17 @@ export const suspend = ( fromTransform((upstream, scope) => Effect.suspend(() => toTransform(evaluate())(upstream, scope))) /** - * 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" * @@ -560,9 +580,17 @@ export 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" * @@ -607,7 +651,7 @@ export const acquireRelease: { * ``` * * @category constructors - * @since 2.0.0 + * @since 4.0.0 */ ( self: Effect.Effect, @@ -625,7 +669,8 @@ export const acquireRelease: { /** * Creates a `Channel` from an iterator. * - * @example + * **Example** (Creating channels from iterators) + * * ```ts * import { Channel } from "effect" * @@ -635,7 +680,7 @@ export const acquireRelease: { * ``` * * @category constructors - * @since 2.0.0 + * @since 4.0.0 */ export const fromIterator = (iterator: LazyArg>): Channel => fromPull( @@ -651,7 +696,8 @@ export const fromIterator = (iterator: LazyArg>): Channel(iterator: LazyArg>): Channel(array: ReadonlyArray): Channel => fromPull(Effect.sync(() => { @@ -671,7 +717,8 @@ export 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" * @@ -681,14 +728,15 @@ export const fromArray = (array: ReadonlyArray): Channel => * ``` * * @category constructors - * @since 2.0.0 + * @since 4.0.0 */ export const fromChunk = (chunk: Chunk.Chunk): Channel => fromArray(Chunk.toReadonlyArray(chunk)) /** * Creates a `Channel` from an iterator that emits arrays of elements. * - * @example + * **Example** (Batching iterator output) + * * ```ts * import { Channel } from "effect" * @@ -709,7 +757,8 @@ export const fromChunk = (chunk: Chunk.Chunk): Channel => fromArray(Chu * // This will emit arrays: [0, 1], [2], then complete with "finished" * ``` * - * @example + * **Example** (Batching generator output) + * * ```ts * import { Channel } from "effect" * @@ -726,8 +775,8 @@ export const fromChunk = (chunk: Chunk.Chunk): Channel => fromArray(Chu * // Emits: [0, 1, 1], [2, 3], then completes * ``` * - * @since 2.0.0 * @category constructors + * @since 4.0.0 */ export const fromIteratorArray = ( iterator: LazyArg>, @@ -759,7 +808,8 @@ export const fromIteratorArray = ( /** * Creates a `Channel` that emits all elements from an iterable. * - * @example + * **Example** (Creating channels from iterables) + * * ```ts * import { Channel } from "effect" * @@ -769,7 +819,7 @@ export const fromIteratorArray = ( * ``` * * @category constructors - * @since 2.0.0 + * @since 4.0.0 */ export const fromIterable = (iterable: Iterable): Channel => fromIterator(() => iterable[Symbol.iterator]()) @@ -777,7 +827,8 @@ export const fromIterable = (iterable: Iterable): Channel(iterable: Iterable): Channel( iterable: Iterable, @@ -797,7 +848,8 @@ export const fromIterableArray = ( /** * Creates a `Channel` that emits a single value and then ends. * - * @example + * **Example** (Creating channels that succeed) + * * ```ts * import { Channel } from "effect" * @@ -813,7 +865,8 @@ export const succeed = (value: A): Channel => fromEffect(Effect.succeed(va /** * Creates a `Channel` that immediately ends with the specified value. * - * @example + * **Example** (Ending with a value) + * * ```ts * import { Channel } from "effect" * @@ -838,12 +891,18 @@ export const endSync = (evaluate: LazyArg): Channel => /** * Creates a `Channel` that emits a single value computed by a lazy evaluation. * - * @example + * **Example** (Computing values lazily) + * * ```ts * import { Channel } from "effect" * - * const channel = Channel.sync(() => 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 @@ -852,9 +911,10 @@ export const endSync = (evaluate: LazyArg): Channel => export const sync = (evaluate: LazyArg): Channel => fromEffect(Effect.sync(evaluate)) /** - * Represents an Channel that emits no elements + * Represents a `Channel` that emits no elements. + * + * **Example** (Using empty channels) * - * @example * ```ts * import { Channel } from "effect" * @@ -870,15 +930,16 @@ export const sync = (evaluate: LazyArg): Channel => fromEffect(Effect.s * shouldEmit ? Channel.succeed("data") : Channel.empty * ``` * - * @since 2.0.0 * @category constructors + * @since 4.0.0 */ export const empty: Channel = fromPull(Effect.succeed(Cause.done())) /** - * Represents an Channel that never completes + * Represents a `Channel` that never completes. + * + * **Example** (Using non-terminating channels) * - * @example * ```ts * import { Channel } from "effect" * @@ -896,15 +957,16 @@ export const empty: Channel = fromPull(Effect.succeed(Cause.done())) * shouldComplete ? Channel.succeed("done") : Channel.never * ``` * - * @since 2.0.0 * @category constructors + * @since 2.0.0 */ export const never: Channel = fromPull(Effect.succeed(Effect.never)) /** * Constructs a channel that fails immediately with the specified error. * - * @example + * **Example** (Failing with an error) + * * ```ts * import { Channel } from "effect" * @@ -927,8 +989,8 @@ export const never: Channel = fromPull(Effect.succeed(Effec * ) * ``` * - * @since 2.0.0 * @category constructors + * @since 2.0.0 */ export const fail = (error: E): Channel => fromPull(Effect.succeed(Effect.fail(error))) @@ -936,7 +998,13 @@ export const fail = (error: E): Channel => fromPull(Effect.s * 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" * @@ -947,26 +1015,34 @@ export const fail = (error: E): Channel => fromPull(Effect.s * }) * * // 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 const failSync = (evaluate: LazyArg): Channel => fromPull(Effect.failSync(evaluate)) /** * 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" * @@ -983,8 +1059,8 @@ export const failSync = (evaluate: LazyArg): Channel => f * const simpleFail = Channel.failCause(failCause) * ``` * - * @since 2.0.0 * @category constructors + * @since 2.0.0 */ export const failCause = (cause: Cause.Cause): Channel => fromPull(Effect.failCause(cause)) @@ -992,25 +1068,27 @@ export const failCause = (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 const failCauseSync = ( evaluate: LazyArg> @@ -1019,7 +1097,8 @@ export const failCauseSync = ( /** * Constructs a channel that fails immediately with the specified defect. * - * @example + * **Example** (Dying with defects) + * * ```ts * import { Channel } from "effect" * @@ -1036,15 +1115,16 @@ export const failCauseSync = ( * }) * ``` * - * @since 2.0.0 * @category constructors + * @since 4.0.0 */ export const die = (defect: unknown): Channel => failCause(Cause.die(defect)) /** - * 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" * @@ -1074,8 +1154,8 @@ export const die = (defect: unknown): Channel => failCause( * ) * ``` * - * @since 2.0.0 * @category constructors + * @since 2.0.0 */ export const fromEffect = ( effect: Effect.Effect @@ -1092,8 +1172,15 @@ export const fromEffect = ( ) /** - * @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 const fromEffectDone = ( effect: Effect.Effect @@ -1101,18 +1188,26 @@ export const fromEffectDone = ( fromPull(Effect.succeed(Effect.flatMap(effect, Cause.done))) /** - * 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 const fromEffectDrain = ( effect: Effect.Effect ): Channel => fromPull(Effect.flatMap(effect, () => Cause.done())) as any /** - * @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 const fromEffectTake = ( effect: Effect.Effect, E2, R> @@ -1120,9 +1215,10 @@ export const fromEffectTake = ( fromPull(Effect.succeed(Effect.flatMap(effect, Take.toPull))) /** - * 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" * @@ -1154,17 +1250,18 @@ export const fromEffectTake = ( * }) * ``` * - * @since 4.0.0 * @category constructors + * @since 2.0.0 */ export const fromQueue = ( queue: Queue.Dequeue ): Channel> => fromPull(Effect.succeed(Queue.take(queue))) /** - * 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" * @@ -1200,24 +1297,28 @@ export const fromQueue = ( * }) * ``` * - * @since 4.0.0 * @category constructors + * @since 4.0.0 */ export const fromQueueArray = ( queue: Queue.Dequeue ): Channel, Exclude> => fromPull(Effect.succeed(Queue.takeAll(queue))) /** + * 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 const identity = (): Channel => fromTransform((upstream, _scope) => Effect.succeed(upstream)) /** - * 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" * @@ -1254,24 +1355,24 @@ export const identity = (): Channel( subscription: PubSub.Subscription ): Channel => fromPull(Effect.succeed(Effect.onInterrupt(PubSub.take(subscription), () => Cause.done()))) /** - * 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" * @@ -1297,7 +1398,8 @@ export const fromSubscription = ( * }) * ``` * - * @example + * **Example** (Processing subscription values in batches) + * * ```ts * import { Channel, Data, Effect, PubSub } from "effect" * @@ -1322,13 +1424,10 @@ export const fromSubscription = ( * }) * ``` * - * @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< @@ -1353,7 +1452,8 @@ export const fromSubscription = ( * average: avg, * min, * max, - * timestamp: Date.now() + * firstTimestamp: Math.min(...metrics.map((m) => m.timestamp)), + * lastTimestamp: Math.max(...metrics.map((m) => m.timestamp)) * } * }) * @@ -1361,8 +1461,8 @@ export const fromSubscription = ( * }) * ``` * - * @since 4.0.0 * @category constructors + * @since 4.0.0 */ export const fromSubscriptionArray = ( subscription: PubSub.Subscription @@ -1370,15 +1470,16 @@ export const fromSubscriptionArray = ( fromPull(Effect.succeed(Effect.onInterrupt(PubSub.takeAll(subscription), () => Cause.done()))) /** - * 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" * @@ -1402,13 +1503,10 @@ export const fromSubscriptionArray = ( * }) * ``` * - * @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) @@ -1417,24 +1515,21 @@ export const fromSubscriptionArray = ( * 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 @@ -1454,7 +1549,7 @@ export const fromSubscriptionArray = ( * return { * ...event, * processed: true, - * processedAt: Date.now() + * processedAt: event.timestamp + 1 * } * } * return event @@ -1464,24 +1559,24 @@ export const fromSubscriptionArray = ( * }) * ``` * - * @since 4.0.0 * @category constructors + * @since 2.0.0 */ export const fromPubSub = ( pubsub: PubSub.PubSub ): Channel => unwrap(Effect.map(PubSub.subscribe(pubsub), fromSubscription)) /** - * 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" * @@ -1506,20 +1601,17 @@ export const fromPubSub = ( * }) * ``` * - * @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*() { @@ -1539,7 +1631,7 @@ export const fromPubSub = ( * batchSize: orderBatch.length, * totalRevenue, * uniqueCustomers: customerCount, - * processedAt: Date.now(), + * firstSubmittedAt: Math.min(...orderBatch.map((order) => order.submittedAt)), * orders: orderBatch * } * }) @@ -1548,14 +1640,10 @@ export const fromPubSub = ( * }) * ``` * - * @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 @@ -1582,7 +1670,7 @@ export const fromPubSub = ( * } * * return { - * batchId: Math.random().toString(36).substr(2, 9), + * batchId: `${timeRange.start}-${timeRange.end}`, * totalEntries: logBatch.length, * errorCount, * warnCount, @@ -1596,15 +1684,22 @@ export const fromPubSub = ( * }) * ``` * - * @since 4.0.0 * @category constructors + * @since 4.0.0 */ export const fromPubSubArray = (pubsub: PubSub.PubSub): Channel> => unwrap(Effect.map(PubSub.subscribe(pubsub), fromSubscriptionArray)) /** - * @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 const fromPubSubTake = ( pubsub: PubSub.PubSub> @@ -1614,8 +1709,8 @@ export const fromPubSubTake = ( /** * Creates a Channel from a Schedule. * - * @since 4.0.0 * @category constructors + * @since 4.0.0 */ export const fromSchedule = ( schedule: Schedule.Schedule @@ -1623,10 +1718,17 @@ export const fromSchedule = ( fromPull(Effect.map(Schedule.toStepWithSleep(schedule), (step) => step(void 0))) /** - * 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 const fromAsyncIterable = ( iterable: AsyncIterable, @@ -1647,10 +1749,17 @@ export const fromAsyncIterable = ( })) /** - * 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 const fromAsyncIterableArray = ( iterable: AsyncIterable, @@ -1660,7 +1769,8 @@ export const fromAsyncIterableArray = ( /** * Maps the output of this channel using the specified function. * - * @example + * **Example** (Mapping channel output) + * * ```ts * import { Channel, Data } from "effect" * @@ -1692,14 +1802,15 @@ export const fromAsyncIterableArray = ( * })) * ``` * + * @category sequencing * @since 2.0.0 - * @category Sequencing */ export const map: { /** * Maps the output of this channel using the specified function. * - * @example + * **Example** (Mapping channel output) + * * ```ts * import { Channel, Data } from "effect" * @@ -1731,8 +1842,8 @@ export const map: { * })) * ``` * + * @category sequencing * @since 2.0.0 - * @category Sequencing */ (f: (o: OutElem, i: number) => OutElem2): ( self: Channel @@ -1740,7 +1851,8 @@ export const map: { /** * Maps the output of this channel using the specified function. * - * @example + * **Example** (Mapping channel output) + * * ```ts * import { Channel, Data } from "effect" * @@ -1772,8 +1884,8 @@ export const map: { * })) * ``` * + * @category sequencing * @since 2.0.0 - * @category Sequencing */ ( self: Channel, @@ -1795,15 +1907,15 @@ export const map: { /** * Maps the done value of this channel using the specified function. * - * @since 2.0.0 - * @category Sequencing + * @category sequencing + * @since 4.0.0 */ export 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 @@ -1811,8 +1923,8 @@ export 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 */ ( self: Channel, @@ -1829,15 +1941,25 @@ export const mapDone: { /** * 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 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 @@ -1845,8 +1967,13 @@ export 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 */ ( self: Channel, @@ -1870,13 +1997,23 @@ const concurrencyIsSequential = ( ) => concurrency === undefined || (concurrency !== "unbounded" && concurrency <= 1) /** - * 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" * @@ -1913,18 +2050,28 @@ const concurrencyIsSequential = ( * ) * ``` * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ export 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" * @@ -1961,8 +2108,8 @@ export const mapEffect: { * ) * ``` * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ ( f: (d: OutElem, i: number) => Effect.Effect, @@ -1974,13 +2121,23 @@ export const mapEffect: { 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" * @@ -2017,8 +2174,8 @@ export const mapEffect: { * ) * ``` * - * @since 2.0.0 * @category sequencing + * @since 2.0.0 */ ( self: Channel, @@ -2166,16 +2323,16 @@ const mapEffectConcurrent = < * 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 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 @@ -2184,8 +2341,8 @@ export 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 */ ( self: Channel, @@ -2206,16 +2363,16 @@ export 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 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 @@ -2224,8 +2381,8 @@ export 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 */ ( self: Channel, @@ -2249,11 +2406,14 @@ export 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" * @@ -2274,19 +2434,22 @@ export const mapInputError: { * // Outputs: 1, 2, 3 (while logging each) * ``` * - * @since 4.0.0 * @category sequencing + * @since 4.0.0 */ export 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" * @@ -2307,8 +2470,8 @@ export 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, @@ -2322,11 +2485,14 @@ export 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" * @@ -2347,8 +2513,8 @@ export const tap: { * // Outputs: 1, 2, 3 (while logging each) * ``` * - * @since 4.0.0 * @category sequencing + * @since 4.0.0 */ ( self: Channel, @@ -2370,13 +2536,18 @@ export const tap: { ) /** - * 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" * @@ -2398,18 +2569,23 @@ export 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 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" * @@ -2431,8 +2607,8 @@ export 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, @@ -2452,13 +2628,18 @@ export const flatMap: { Env1 | Env > /** - * 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" * @@ -2480,8 +2661,8 @@ export 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 */ < OutElem, @@ -2645,7 +2826,8 @@ const flatMapConcurrent = < * 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" * @@ -2662,15 +2844,16 @@ const flatMapConcurrent = < * // Outputs: 1, 2, 3, then "Completed processing" * ``` * - * @since 2.0.0 * @category sequencing + * @since 4.0.0 */ export 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" * @@ -2687,8 +2870,8 @@ export const concatWith: { * // Outputs: 1, 2, 3, then "Completed processing" * ``` * - * @since 2.0.0 * @category sequencing + * @since 4.0.0 */ ( f: (leftover: Types.NoInfer) => Channel @@ -2707,7 +2890,8 @@ export 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" * @@ -2724,8 +2908,8 @@ export const concatWith: { * // Outputs: 1, 2, 3, then "Completed processing" * ``` * - * @since 2.0.0 * @category sequencing + * @since 4.0.0 */ < OutElem, @@ -2805,7 +2989,8 @@ export 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" * @@ -2823,15 +3008,16 @@ export const concatWith: { * // Outputs: 1, 2, 3, "a", "b", "c" * ``` * - * @since 2.0.0 * @category sequencing + * @since 4.0.0 */ export 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" * @@ -2849,8 +3035,8 @@ export const concat: { * // Outputs: 1, 2, 3, "a", "b", "c" * ``` * - * @since 2.0.0 * @category sequencing + * @since 4.0.0 */ (that: Channel): ( self: Channel @@ -2867,7 +3053,8 @@ export 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" * @@ -2885,8 +3072,8 @@ export const concat: { * // Outputs: 1, 2, 3, "a", "b", "c" * ``` * - * @since 2.0.0 * @category sequencing + * @since 4.0.0 */ < OutElem, @@ -2944,25 +3131,39 @@ export const concat: { > => concatWith(self, (_) => that)) /** - * 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 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, @@ -2982,14 +3183,21 @@ export const combine: { 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 */ < OutElem, @@ -3079,13 +3287,31 @@ export const combine: { }))) /** - * @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 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 @@ -3101,8 +3327,17 @@ export const orElseIfEmpty: { Env1 | Env > /** - * @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 */ < OutElem, @@ -3186,9 +3421,10 @@ export const orElseIfEmpty: { )) /** - * Flatten a channel of channels. + * Flattens a channel of channels. + * + * **Example** (Flattening nested channels) * - * @example * ```ts * import { Channel, Data } from "effect" * @@ -3209,8 +3445,8 @@ export const orElseIfEmpty: { * // Outputs: 1, 2, 3, 4, 5, 6 * ``` * - * @since 2.0.0 * @category constructors + * @since 2.0.0 */ export const flatten = < OutElem, @@ -3242,7 +3478,8 @@ export const flatten = < /** * 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" * @@ -3263,8 +3500,8 @@ export const flatten = < * // Outputs: 1, 2, 3, 4, 5, 6, 7, 8, 9 * ``` * + * @category transforming * @since 4.0.0 - * @category utils */ export const flattenArray = < OutElem, @@ -3306,8 +3543,16 @@ export const flattenArray = < }) /** + * 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 const flattenTake = < OutElem, @@ -3328,7 +3573,8 @@ export const flattenTake = < * 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" * @@ -3342,8 +3588,8 @@ export const flattenTake = < * // Useful for consuming side effects without collecting output * ``` * - * @since 2.0.0 * @category constructors + * @since 2.0.0 */ export const drain = < OutElem, @@ -3369,15 +3615,15 @@ export const drain = < /** * Repeats this channel according to the provided schedule. * + * @category repetition * @since 4.0.0 - * @category utils */ export const repeat: { /** * Repeats this channel according to the provided schedule. * + * @category repetition * @since 4.0.0 - * @category utils */ ( schedule: @@ -3391,8 +3637,8 @@ export const repeat: { /** * Repeats this channel according to the provided schedule. * + * @category repetition * @since 4.0.0 - * @category utils */ ( self: Channel, @@ -3441,28 +3687,58 @@ export const repeat: { /** * Repeats this channel forever. * + * @category repetition * @since 4.0.0 - * @category utils */ export const forever = ( self: Channel ): Channel => concatWith(self, () => forever(self)) /** + * 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 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, @@ -3493,7 +3769,8 @@ export 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" * @@ -3513,15 +3790,16 @@ export const schedule: { * // Outputs: 1, 2, 3 (all typed as numbers) * ``` * - * @since 2.0.0 - * @category Filtering + * @category filtering + * @since 4.0.0 */ export 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" * @@ -3541,8 +3819,8 @@ export 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 @@ -3551,7 +3829,8 @@ export 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" * @@ -3571,8 +3850,8 @@ export 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 @@ -3581,7 +3860,8 @@ export 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" * @@ -3601,8 +3881,8 @@ export const filter: { * // Outputs: 1, 2, 3 (all typed as numbers) * ``` * - * @since 2.0.0 - * @category Filtering + * @category filtering + * @since 4.0.0 */ ( self: Channel, @@ -3612,7 +3892,8 @@ export 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" * @@ -3632,8 +3913,8 @@ export const filter: { * // Outputs: 1, 2, 3 (all typed as numbers) * ``` * - * @since 2.0.0 - * @category Filtering + * @category filtering + * @since 4.0.0 */ ( self: Channel, @@ -3656,20 +3937,71 @@ export const filter: { )) /** + * 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 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, @@ -3693,20 +4025,59 @@ export const filterMap: { )) /** + * 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 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, @@ -3733,20 +4104,74 @@ export const filterEffect: { )) /** + * 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 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, @@ -3776,7 +4201,8 @@ export 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" * @@ -3804,15 +4230,16 @@ export const filterMapEffect: { * // Outputs: [2, 4] (the arrays [1,3,5] and [7,9] are discarded) * ``` * + * @category filtering * @since 4.0.0 - * @category Filtering */ export 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" * @@ -3840,8 +4267,8 @@ export 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> @@ -3850,7 +4277,8 @@ export 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" * @@ -3878,8 +4306,8 @@ export 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> @@ -3888,7 +4316,8 @@ export 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" * @@ -3916,8 +4345,8 @@ export 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>, @@ -3927,7 +4356,8 @@ export 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" * @@ -3955,8 +4385,8 @@ export 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>, @@ -3983,20 +4413,44 @@ export const filterArray: { )))) /** + * 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 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>, @@ -4024,13 +4478,41 @@ export const filterMapArray: { )))) /** + * 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 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 @@ -4038,8 +4520,22 @@ export const filterArrayEffect: { 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>, @@ -4060,20 +4556,62 @@ export const filterArrayEffect: { })) /** + * 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 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>, @@ -4098,9 +4636,10 @@ export const filterMapArrayEffect: { )))) /** - * 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" * @@ -4131,14 +4670,15 @@ export const filterMapArrayEffect: { * ) * ``` * - * @since 2.0.0 - * @category Sequencing + * @category sequencing + * @since 4.0.0 */ export 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" * @@ -4169,8 +4709,8 @@ export const mapAccum: { * ) * ``` * - * @since 2.0.0 - * @category Sequencing + * @category sequencing + * @since 4.0.0 */ ( initial: LazyArg, @@ -4200,9 +4740,10 @@ export const mapAccum: { Env | R > /** - * 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" * @@ -4233,8 +4774,8 @@ export const mapAccum: { * ) * ``` * - * @since 2.0.0 - * @category Sequencing + * @category sequencing + * @since 4.0.0 */ ( self: Channel, @@ -4312,10 +4853,11 @@ export const mapAccum: { ) /** - * 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" * @@ -4337,15 +4879,16 @@ export 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 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" * @@ -4367,8 +4910,8 @@ export 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): < OutErr, @@ -4387,10 +4930,11 @@ export const scan: { Env > /** - * 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" * @@ -4412,8 +4956,8 @@ export 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, @@ -4428,10 +4972,16 @@ export const scan: { scanEffect(self, initial, (s, a) => Effect.succeed(f(s, a)))) /** - * 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" * @@ -4468,16 +5018,22 @@ export const scan: { * ) * ``` * - * @since 2.0.0 - * @category Sequencing + * @category sequencing + * @since 4.0.0 */ export 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")<{ @@ -4513,8 +5069,8 @@ export const scanEffect: { * ) * ``` * - * @since 2.0.0 - * @category Sequencing + * @category sequencing + * @since 4.0.0 */ (initial: S, f: (s: S, a: Types.NoInfer) => Effect.Effect): < OutErr, @@ -4533,10 +5089,16 @@ export const scanEffect: { Env | R > /** - * 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" * @@ -4573,8 +5135,8 @@ export const scanEffect: { * ) * ``` * - * @since 2.0.0 - * @category Sequencing + * @category sequencing + * @since 4.0.0 */ ( self: Channel, @@ -4610,7 +5172,8 @@ export 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" * @@ -4638,15 +5201,16 @@ export const scanEffect: { * // The channel recovers gracefully from errors * ``` * - * @since 4.0.0 - * @category Error handling + * @category error handling + * @since 2.0.0 */ export 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" * @@ -4674,8 +5238,8 @@ export 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 @@ -4699,7 +5263,8 @@ export 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" * @@ -4727,8 +5292,8 @@ export const catchCause: { * // The channel recovers gracefully from errors * ``` * - * @since 4.0.0 - * @category Error handling + * @category error handling + * @since 2.0.0 */ < OutElem, @@ -4808,13 +5373,39 @@ export const catchCause: { })) /** + * 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 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): < OutElem, @@ -4833,8 +5424,21 @@ export const tapCause: { Env | R > /** + * 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 */ < OutElem, @@ -4887,16 +5491,46 @@ export 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 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 */ < OutErr, @@ -4930,8 +5564,23 @@ export 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 */ < OutElem, @@ -5009,13 +5658,49 @@ export const catchCauseIf: { )) /** + * 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 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 */ < OutErr, @@ -5051,8 +5736,26 @@ export const catchCauseFilter: { 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 */ < OutElem, @@ -5216,20 +5919,38 @@ 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 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): < OutElem, @@ -5248,8 +5969,16 @@ export const tapError: { Env | R > /** + * 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 */ < OutElem, @@ -5307,13 +6036,49 @@ export const tapError: { )) /** + * 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 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 */ < OutErr, @@ -5325,8 +6090,8 @@ export const catchIf: { InErr1, InDone1, Env1, - OutElem2 = never, - OutErr2 = Exclude, + OutElem2 = Types.unassigned, + OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, @@ -5348,8 +6113,8 @@ export const catchIf: { InDone, Env >(self: Channel) => Channel< - OutElem | OutElem1 | OutElem2, - OutErr1 | OutErr2, + OutElem | OutElem1 | Exclude, + OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? Exclude : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, @@ -5357,8 +6122,26 @@ export const catchIf: { 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 */ < OutErr, @@ -5369,8 +6152,8 @@ export const catchIf: { InErr1, InDone1, Env1, - OutElem2 = never, - OutErr2 = OutErr, + OutElem2 = Types.unassigned, + OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, @@ -5392,8 +6175,8 @@ export const catchIf: { InDone, Env >(self: Channel) => Channel< - OutElem | OutElem1 | OutElem2, - OutErr1 | OutErr2, + OutElem | OutElem1 | Exclude, + OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? OutErr : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, @@ -5401,8 +6184,26 @@ export const catchIf: { 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 */ < OutElem, @@ -5420,8 +6221,8 @@ export const catchIf: { InErr1, InDone1, Env1, - OutElem2 = never, - OutErr2 = Exclude, + OutElem2 = Types.unassigned, + OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, @@ -5437,8 +6238,8 @@ export const catchIf: { ) => Channel) | undefined ): Channel< - OutElem | OutElem1 | OutElem2, - OutErr1 | OutErr2, + OutElem | OutElem1 | Exclude, + OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? Exclude : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, @@ -5446,8 +6247,26 @@ export const catchIf: { 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 */ < OutElem, @@ -5464,8 +6283,8 @@ export const catchIf: { InErr1, InDone1, Env1, - OutElem2 = never, - OutErr2 = OutErr, + OutElem2 = Types.unassigned, + OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, @@ -5481,8 +6300,8 @@ export const catchIf: { ) => Channel) | undefined ): Channel< - OutElem | OutElem1 | OutElem2, - OutErr1 | OutErr2, + OutElem | OutElem1 | Exclude, + OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? OutErr : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, @@ -5549,13 +6368,47 @@ export const catchIf: { )) /** + * 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 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 */ < OutErr, @@ -5568,8 +6421,8 @@ export const catchFilter: { InErr1, InDone1, Env1, - OutElem2 = never, - OutErr2 = X, + OutElem2 = Types.unassigned, + OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, @@ -5591,8 +6444,8 @@ export const catchFilter: { InDone, Env >(self: Channel) => Channel< - OutElem | OutElem1 | OutElem2, - OutErr1 | OutErr2, + OutElem | OutElem1 | Exclude, + OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? X : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, @@ -5600,8 +6453,25 @@ export const catchFilter: { 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 */ < OutElem, @@ -5620,8 +6490,8 @@ export const catchFilter: { InErr1, InDone1, Env1, - OutElem2 = never, - OutErr2 = X, + OutElem2 = Types.unassigned, + OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, @@ -5637,8 +6507,8 @@ export const catchFilter: { ) => Channel) | undefined ): Channel< - OutElem | OutElem1 | OutElem2, - OutErr1 | OutErr2, + OutElem | OutElem1 | Exclude, + OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? X : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, @@ -5708,13 +6578,29 @@ export const catchFilter: { )) /** + * 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 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 */ < OutErr, @@ -5726,8 +6612,8 @@ export const catchTag: { InErr1, InDone1, Env1, - OutElem2 = never, - OutErr2 = Types.ExcludeTag ? K[number] : K>, + OutElem2 = Types.unassigned, + OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, @@ -5751,8 +6637,12 @@ export const catchTag: { InDone, Env >(self: Channel) => Channel< - OutElem | OutElem1 | OutElem2, - OutErr1 | OutErr2, + OutElem | OutElem1 | Exclude, + | OutErr1 + | OutErr2 + | (OutElem2 extends Types.unassigned + ? Types.ExcludeTag ? K[number] : K> + : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, @@ -5760,8 +6650,16 @@ export const catchTag: { 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 */ < OutElem, @@ -5779,8 +6677,8 @@ export const catchTag: { InErr1, InDone1, Env1, - OutElem2 = never, - OutErr2 = Types.ExcludeTag ? K[number] : K>, + OutElem2 = Types.unassigned, + OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, @@ -5798,8 +6696,12 @@ export const catchTag: { ) => Channel) | undefined ): Channel< - OutElem | OutElem1 | OutElem2, - OutErr1 | OutErr2, + OutElem | OutElem1 | Exclude, + | OutErr1 + | OutErr2 + | (OutElem2 extends Types.unassigned + ? Types.ExcludeTag ? K[number] : K> + : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, @@ -5858,7 +6760,8 @@ export const catchTag: { /** * Catches a specific reason within a tagged error. * - * @example + * **Example** (Recovering from nested reasons) + * * ```ts * import { Channel, Data } from "effect" * @@ -5885,14 +6788,15 @@ export const catchTag: { * ) * ``` * + * @category error handling * @since 4.0.0 - * @category Error handling */ export const catchReason: { /** * Catches a specific reason within a tagged error. * - * @example + * **Example** (Recovering from nested reasons) + * * ```ts * import { Channel, Data } from "effect" * @@ -5919,8 +6823,8 @@ export const catchReason: { * ) * ``` * + * @category error handling * @since 4.0.0 - * @category Error handling */ < OutErr, @@ -5964,7 +6868,10 @@ export const catchReason: { self: Channel ) => Channel< OutElem | OutElem1 | Exclude, - (OutElem2 extends Types.unassigned ? OutErr : Types.ExcludeTag) | OutErr1 | OutErr2, + | Types.ExcludeTag + | OutErr1 + | OutErr2 + | (OutElem2 extends Types.unassigned ? Types.ExtractTag : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, @@ -5974,7 +6881,8 @@ export const catchReason: { /** * Catches a specific reason within a tagged error. * - * @example + * **Example** (Recovering from nested reasons) + * * ```ts * import { Channel, Data } from "effect" * @@ -6001,8 +6909,8 @@ export const catchReason: { * ) * ``` * + * @category error handling * @since 4.0.0 - * @category Error handling */ < OutElem, @@ -6044,7 +6952,10 @@ export const catchReason: { | undefined ): Channel< OutElem | OutElem1 | Exclude, - (OutElem2 extends Types.unassigned ? OutErr : Types.ExcludeTag) | OutErr1 | OutErr2, + | Types.ExcludeTag + | OutErr1 + | OutErr2 + | (OutElem2 extends Types.unassigned ? Types.ExtractTag : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, @@ -6091,7 +7002,10 @@ export const catchReason: { | undefined ): Channel< OutElem | OutElem1 | Exclude, - (OutElem2 extends Types.unassigned ? OutErr : Types.ExcludeTag) | OutErr1 | OutErr2, + | Types.ExcludeTag + | OutErr1 + | OutErr2 + | (OutElem2 extends Types.unassigned ? Types.ExtractTag : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, @@ -6123,15 +7037,15 @@ export const catchReason: { /** * Catches multiple reasons within a tagged error using an object of handlers. * + * @category error handling * @since 4.0.0 - * @category Error handling */ export const catchReasons: { /** * Catches multiple reasons within a tagged error using an object of handlers. * + * @category error handling * @since 4.0.0 - * @category Error handling */ < K extends Types.Tags, @@ -6167,8 +7081,9 @@ export const catchReasons: { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? OutElem1 : never }[keyof Cases], - | (OutElem2 extends Types.unassigned ? OutErr : Types.ExcludeTag) + | Types.ExcludeTag | OutErr2 + | (OutElem2 extends Types.unassigned ? Types.ExtractTag : never) | { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? OutErr1 : never @@ -6207,8 +7122,8 @@ export const catchReasons: { /** * Catches multiple reasons within a tagged error using an object of handlers. * + * @category error handling * @since 4.0.0 - * @category Error handling */ < OutElem, @@ -6249,8 +7164,9 @@ export const catchReasons: { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? OutElem1 : never }[keyof Cases], - | (OutElem2 extends Types.unassigned ? OutErr : Types.ExcludeTag) + | Types.ExcludeTag | OutErr2 + | (OutElem2 extends Types.unassigned ? Types.ExtractTag : never) | { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? OutErr1 : never @@ -6309,7 +7225,8 @@ export 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" * @@ -6332,14 +7249,15 @@ export const catchReasons: { * const unwrapped = channel.pipe(Channel.unwrapReason("AiError")) * ``` * + * @category error handling * @since 4.0.0 - * @category Error handling */ export 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" * @@ -6362,8 +7280,8 @@ export const unwrapReason: { * const unwrapped = channel.pipe(Channel.unwrapReason("AiError")) * ``` * + * @category error handling * @since 4.0.0 - * @category Error handling */ < K extends TagsWithReason, @@ -6382,7 +7300,8 @@ export 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" * @@ -6405,8 +7324,8 @@ export const unwrapReason: { * const unwrapped = channel.pipe(Channel.unwrapReason("AiError")) * ``` * + * @category error handling * @since 4.0.0 - * @category Error handling */ < OutElem, @@ -6462,8 +7381,8 @@ export 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 const mapError: { /** @@ -6471,8 +7390,8 @@ export 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 @@ -6482,8 +7401,8 @@ export 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, @@ -6498,7 +7417,8 @@ export 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" * @@ -6515,8 +7435,8 @@ export 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 const orDie = < OutElem, @@ -6533,10 +7453,12 @@ export const orDie = < /** * 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 const ignore: < Arg extends Channel | { @@ -6588,10 +7510,17 @@ const ignoreCause_ = < /** * Ignores all errors in the channel including defects, converting them to an empty channel. * + * **When to use** + * + * Use when a channel should become best-effort and all failure causes, including + * defects and interruptions, can be converted to empty output. + * + * **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 const ignoreCause: < Arg extends Channel | { @@ -6625,16 +7554,16 @@ export const ignoreCause: < * 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 */ export const retry: { /** * 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 */ ( schedule: @@ -6651,8 +7580,8 @@ export const retry: { * 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, @@ -6707,13 +7636,17 @@ export const retry: { })) /** - * 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" * @@ -6733,18 +7666,22 @@ export const retry: { * // Outputs: "value-1", "value-2", "value-3" * ``` * - * @since 2.0.0 * @category sequencing + * @since 4.0.0 */ export 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" * @@ -6764,8 +7701,8 @@ export const switchMap: { * // Outputs: "value-1", "value-2", "value-3" * ``` * - * @since 2.0.0 * @category sequencing + * @since 4.0.0 */ ( f: (d: OutElem) => Channel, @@ -6785,13 +7722,17 @@ export const switchMap: { Env1 | Env > /** - * 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" * @@ -6811,8 +7752,8 @@ export const switchMap: { * // Outputs: "value-1", "value-2", "value-3" * ``` * - * @since 2.0.0 * @category sequencing + * @since 4.0.0 */ < OutElem, @@ -6891,7 +7832,13 @@ export 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" * @@ -6915,14 +7862,20 @@ export const switchMap: { * // Outputs: 1, 2, 3, 4, 5, 6 (order may vary due to concurrency) * ``` * + * @category combining * @since 2.0.0 - * @category utils */ export 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" * @@ -6946,8 +7899,8 @@ export const mergeAll: { * // Outputs: 1, 2, 3, 4, 5, 6 (order may vary due to concurrency) * ``` * + * @category combining * @since 2.0.0 - * @category utils */ ( options: { @@ -6977,7 +7930,13 @@ export 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" * @@ -7001,8 +7960,8 @@ export 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< @@ -7066,7 +8025,13 @@ export const mergeAll: { const queue = yield* Queue.bounded>( bufferSize @@ -7180,7 +8151,8 @@ export 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" * @@ -7191,8 +8163,8 @@ export 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" @@ -7200,7 +8172,8 @@ 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" * @@ -7221,15 +8194,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 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" * @@ -7250,8 +8224,8 @@ export 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, @@ -7273,7 +8247,8 @@ export 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" * @@ -7294,8 +8269,8 @@ export const merge: { * // Order may vary: 1, "a", 2, "b", 3, "c" * ``` * - * @since 2.0.0 - * @category utils + * @category combining + * @since 4.0.0 */ < OutElem, @@ -7363,7 +8338,8 @@ export 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" * @@ -7384,14 +8360,15 @@ export const merge: { * // Order may vary: 1, "a", 2, "b", 3, "c" * ``` * - * @since 2.0.0 - * @category utils + * @category combining + * @since 4.0.0 */ OutElem | OutElem1, /** * 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" * @@ -7412,8 +8389,8 @@ export const merge: { * // Order may vary: 1, "a", 2, "b", 3, "c" * ``` * - * @since 2.0.0 - * @category utils + * @category combining + * @since 4.0.0 */ OutErr | OutErr1 | Cause.Done>(0) yield* Scope.addFinalizer(forkedScope, Queue.shutdown(queue)) @@ -7473,20 +8450,59 @@ export const merge: { }))) /** + * 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 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, @@ -7507,12 +8523,14 @@ export 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" @@ -7526,8 +8544,8 @@ export const mergeEffect: { * })) * ``` * - * @since 2.0.0 * @category String manipulation + * @since 2.0.0 */ export const splitLines = (): Channel< Arr.NonEmptyReadonlyArray, @@ -7632,8 +8650,16 @@ export const splitLines = (): Channel< ) /** - * @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 const decodeText = (encoding?: string, options?: TextDecoderOptions): Channel< Arr.NonEmptyReadonlyArray, @@ -7646,13 +8672,20 @@ export const decodeText = (encoding?: string, options?: TextDecoderOp fromTransform((upstream, _scope) => Effect.sync(() => { const decoder = new TextDecoder(encoding, options) - return Effect.map(upstream, Arr.map((line) => decoder.decode(line))) + const streamOptions = { stream: true } + return Effect.map(upstream, Arr.map((line) => decoder.decode(line, streamOptions))) }) ) /** - * @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 const encodeText = (): Channel< Arr.NonEmptyReadonlyArray, @@ -7675,7 +8708,8 @@ export const encodeText = (): Channel< * 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" * @@ -7693,8 +8727,8 @@ export const encodeText = (): Channel< * // Outputs: 2, 4, 6 * ``` * + * @category sequencing * @since 2.0.0 - * @category utils */ export const pipeTo: { /** @@ -7703,7 +8737,8 @@ export 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" * @@ -7721,8 +8756,8 @@ export const pipeTo: { * // Outputs: 2, 4, 6 * ``` * + * @category sequencing * @since 2.0.0 - * @category utils */ (that: Channel): ( self: Channel @@ -7733,7 +8768,8 @@ export 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" * @@ -7751,8 +8787,8 @@ export const pipeTo: { * // Outputs: 2, 4, 6 * ``` * + * @category sequencing * @since 2.0.0 - * @category utils */ ( self: Channel, @@ -7774,7 +8810,8 @@ export 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" * @@ -7792,8 +8829,8 @@ export const pipeTo: { * // Source errors are preserved and not sent to transform channel * ``` * + * @category sequencing * @since 2.0.0 - * @category utils */ export const pipeToOrFail: { /** @@ -7801,7 +8838,8 @@ export 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" * @@ -7819,8 +8857,8 @@ export const pipeToOrFail: { * // Source errors are preserved and not sent to transform channel * ``` * + * @category sequencing * @since 2.0.0 - * @category utils */ (that: Channel): ( self: Channel @@ -7830,7 +8868,8 @@ export 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" * @@ -7848,8 +8887,8 @@ export const pipeToOrFail: { * // Source errors are preserved and not sent to transform channel * ``` * + * @category sequencing * @since 2.0.0 - * @category utils */ ( self: Channel, @@ -7885,7 +8924,8 @@ export 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" * @@ -7904,8 +8944,8 @@ export const pipeToOrFail: { * // The resulting channel outputs: 1, 2, 3 * ``` * - * @since 2.0.0 * @category constructors + * @since 2.0.0 */ export const unwrap = ( channel: Effect.Effect, E, R> @@ -7923,62 +8963,90 @@ export const unwrap = ( self: Channel ): Channel> => - fromTransformBracket((upstream, scope, forkedScope) => Scope.provide(toTransform(self)(upstream, scope), forkedScope)) + fromTransformBracket((upstream, scope, forkedScope) => + Effect.map( + Scope.provide(toTransform(self)(upstream, scope), forkedScope), + Scope.provide(forkedScope) + ) + ) /** - * 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 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: ( @@ -7988,28 +9056,38 @@ export const embedInput: { 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 */ ( self: Channel, @@ -8034,19 +9112,55 @@ export const embedInput: { ) /** - * 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 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" } | { @@ -8057,11 +9171,29 @@ export const buffer: { 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, @@ -8080,18 +9212,54 @@ export const buffer: { fromTransform(Effect.fnUntraced(function*(upstream, scope) { const pull = yield* toTransform(self)(upstream, scope) const queue = yield* Queue.make>({ capacity: options.capacity === "unbounded" ? undefined : options.capacity, @@ -8108,19 +9276,59 @@ export const buffer: { }))) /** - * 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 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" } | { @@ -8131,11 +9339,31 @@ export const bufferArray: { 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>, @@ -8154,18 +9382,58 @@ export const bufferArray: { fromTransform(Effect.fnUntraced(function*(upstream, scope) { const pull = yield* toTransform(self)(upstream, scope) const queue = yield* Queue.make>({ capacity: options.capacity === "unbounded" ? undefined : options.capacity, @@ -8182,44 +9450,59 @@ export const bufferArray: { }))) /** - * 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 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, @@ -8236,20 +9519,47 @@ export const interruptWhen: { )) /** + * 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 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, @@ -8275,13 +9585,27 @@ export const haltWhen: { }))) /** + * 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 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 @@ -8289,8 +9613,15 @@ export const onError: { 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, @@ -8303,11 +9634,11 @@ export const onError: { onExit(self, (exit) => Exit.isFailure(exit) ? finalizer(exit.cause) : Effect.void)) /** - * 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" * @@ -8328,16 +9659,16 @@ export const onError: { * }) * ``` * + * @category resource management * @since 4.0.0 - * @category utils */ export 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" * @@ -8358,8 +9689,8 @@ export const onExit: { * }) * ``` * + * @category resource management * @since 4.0.0 - * @category utils */ ( finalizer: (e: Exit.Exit) => Effect.Effect @@ -8367,11 +9698,11 @@ export const onExit: { 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" * @@ -8392,8 +9723,8 @@ export const onExit: { * }) * ``` * + * @category resource management * @since 4.0.0 - * @category utils */ ( self: Channel, @@ -8410,20 +9741,41 @@ export const onExit: { )) /** + * 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 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, @@ -8435,20 +9787,59 @@ export const onStart: { ): Channel => unwrap(Effect.as(onStart, self))) /** + * 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 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, @@ -8469,20 +9860,44 @@ export const onFirst: { }))) /** + * 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 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, @@ -8499,11 +9914,11 @@ export const onEnd: { )))) /** - * 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" * @@ -8521,16 +9936,16 @@ export const onEnd: { * ) * ``` * + * @category resource management * @since 2.0.0 - * @category utils */ export 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" * @@ -8548,18 +9963,18 @@ export 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" * @@ -8577,8 +9992,8 @@ export const ensuring: { * ) * ``` * + * @category resource management * @since 2.0.0 - * @category utils */ ( self: Channel, @@ -8613,10 +10028,10 @@ const runWith = < }) /** - * Create a channel from the specified services. + * Creates a channel from the specified services. * + * @category services * @since 2.0.0 - * @category Services */ export const contextWith = ( f: (context: Context.Context) => Channel @@ -8626,32 +10041,29 @@ export const contextWith = (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, @@ -8669,20 +10081,29 @@ export const provideContext: { )) /** - * @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 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, @@ -8702,20 +10123,56 @@ export const provideService: { )) /** + * 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 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, @@ -8735,13 +10192,31 @@ export const provideServiceEffect: { )) /** + * 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 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, @@ -8752,8 +10227,17 @@ export const provide: { 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, @@ -8783,20 +10267,44 @@ export const provide: { )) /** - * @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 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, @@ -8814,20 +10322,41 @@ export const updateContext: { )) /** + * 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 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, @@ -8847,20 +10376,41 @@ export const updateService: { ))) /** - * @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 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, @@ -8895,8 +10445,10 @@ const withSpanImpl = ( ) /** + * The starting channel for Do notation, emitting an empty object. + * + * @category do notation * @since 4.0.0 - * @category Do notation */ export const Do: Channel<{}> = succeed({}) @@ -8940,26 +10492,47 @@ const let_: { InErr, InDone, R -> => map(self, (elem) => (({ - ...elem, - [name]: f(elem) -}) as any))) +> => + map(self, (elem) => (({ + ...elem, + [name]: f(elem) + }) as any))) 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 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, @@ -8980,8 +10553,17 @@ export const bind: { 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 */ < OutElem extends object, @@ -9056,13 +10638,35 @@ export const bind: { )) /** + * 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 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 @@ -9076,8 +10680,19 @@ export const bindTo: { 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, @@ -9107,7 +10722,8 @@ export const bindTo: { /** * Runs a channel and counts the number of elements it outputs. * - * @example + * **Example** (Counting channel output) + * * ```ts * import { Channel, Data } from "effect" * @@ -9124,8 +10740,8 @@ export const bindTo: { * // Effect.runSync(countEffect) // Returns: 5 * ``` * - * @since 2.0.0 * @category execution + * @since 4.0.0 */ export const runCount = ( self: Channel @@ -9134,7 +10750,8 @@ export const runCount = ( /** * 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" * @@ -9155,8 +10772,8 @@ export const runCount = ( * // Effect.runSync(drainEffect) // Returns: "completed" * ``` * - * @since 2.0.0 * @category execution + * @since 2.0.0 */ export const runDrain = ( self: Channel @@ -9165,7 +10782,8 @@ export const runDrain = ( /** * 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" * @@ -9185,14 +10803,15 @@ export const runDrain = ( * // Logs: "Processing: 1", "Processing: 2", "Processing: 3" * ``` * - * @since 2.0.0 * @category execution + * @since 4.0.0 */ export const runForEach: { /** * 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" * @@ -9212,8 +10831,8 @@ export const runForEach: { * // Logs: "Processing: 1", "Processing: 2", "Processing: 3" * ``` * - * @since 2.0.0 * @category execution + * @since 4.0.0 */ (f: (o: OutElem) => Effect.Effect): ( self: Channel @@ -9221,7 +10840,8 @@ export const runForEach: { /** * 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" * @@ -9241,8 +10861,8 @@ export const runForEach: { * // Logs: "Processing: 1", "Processing: 2", "Processing: 3" * ``` * - * @since 2.0.0 * @category execution + * @since 4.0.0 */ ( self: Channel, @@ -9258,20 +10878,44 @@ export const runForEach: { ) /** - * @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 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, @@ -9294,7 +10938,8 @@ export const runForEachWhile: { /** * Runs a channel and collects all output elements into an array. * - * @example + * **Example** (Collecting channel output) + * * ```ts * import { Channel, Data } from "effect" * @@ -9311,8 +10956,8 @@ export const runForEachWhile: { * // Effect.runSync(collectEffect) // Returns: [1, 2, 3, 4, 5] * ``` * - * @since 2.0.0 * @category execution + * @since 2.0.0 */ export const runCollect = ( self: Channel @@ -9325,16 +10970,24 @@ export const runCollect = ( /** * Runs a channel and outputs the done value. * - * @since 4.0.0 * @category execution + * @since 4.0.0 */ export const runDone = ( self: Channel ): Effect.Effect => runWith(self, identity_, Effect.succeed) /** - * @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 const runHead = ( self: Channel @@ -9352,8 +11005,16 @@ export const runHead = ( }) /** - * @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 const runLast = ( self: Channel @@ -9378,7 +11039,8 @@ export const runLast = ( /** * Runs a channel and folds over all output elements with an accumulator. * - * @example + * **Example** (Folding channel output) + * * ```ts * import { Channel, Data } from "effect" * @@ -9395,14 +11057,15 @@ export const runLast = ( * // Effect.runSync(sumEffect) // Returns: 15 * ``` * - * @since 2.0.0 * @category execution + * @since 4.0.0 */ export const runFold: { /** * Runs a channel and folds over all output elements with an accumulator. * - * @example + * **Example** (Folding channel output) + * * ```ts * import { Channel, Data } from "effect" * @@ -9419,8 +11082,8 @@ export const runFold: { * // Effect.runSync(sumEffect) // Returns: 15 * ``` * - * @since 2.0.0 * @category execution + * @since 4.0.0 */ (initial: LazyArg, f: (acc: Z, o: OutElem) => Z): ( self: Channel @@ -9428,7 +11091,8 @@ export const runFold: { /** * Runs a channel and folds over all output elements with an accumulator. * - * @example + * **Example** (Folding channel output) + * * ```ts * import { Channel, Data } from "effect" * @@ -9445,8 +11109,8 @@ export const runFold: { * // Effect.runSync(sumEffect) // Returns: 15 * ``` * - * @since 2.0.0 * @category execution + * @since 4.0.0 */ ( self: Channel, @@ -9475,20 +11139,59 @@ export const runFold: { })) /** - * @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 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, @@ -9520,9 +11223,16 @@ export const runFoldEffect: { })) /** - * 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" * @@ -9541,8 +11251,8 @@ export const runFoldEffect: { * // Use the Pull to manually consume elements * ``` * + * @category destructors * @since 2.0.0 - * @category Destructors */ export const toPull: ( self: Channel @@ -9570,7 +11280,8 @@ export const toPull: ( /** * 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" * @@ -9589,8 +11300,8 @@ export const toPull: ( * }) * ``` * + * @category destructors * @since 4.0.0 - * @category Destructors */ export const toPullScoped = ( self: Channel, @@ -9598,20 +11309,44 @@ export const toPullScoped = ( ): Effect.Effect, never, Env> => toTransform(self)(Cause.done(), scope) /** + * 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 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, @@ -9640,20 +11375,47 @@ export const runIntoQueue: { ) /** + * 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 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>, @@ -9682,9 +11444,17 @@ export const runIntoQueueArray: { ) /** - * 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" * @@ -9702,14 +11472,22 @@ export const runIntoQueueArray: { * // Multiple consumers can read from the queue * ``` * - * @since 4.0.0 - * @category Destructors + * @category destructors + * @since 2.0.0 */ export 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" * @@ -9727,8 +11505,8 @@ export const toQueue: { * // Multiple consumers can read from the queue * ``` * - * @since 4.0.0 - * @category Destructors + * @category destructors + * @since 2.0.0 */ ( options: { @@ -9741,9 +11519,17 @@ export const toQueue: { 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" * @@ -9761,8 +11547,8 @@ export const toQueue: { * // Multiple consumers can read from the queue * ``` * - * @since 4.0.0 - * @category Destructors + * @category destructors + * @since 2.0.0 */ ( self: Channel, @@ -9786,9 +11572,17 @@ export const toQueue: { ) { const scope = yield* Effect.scope const queue = yield* Queue.make({ capacity: typeof options.capacity === "number" ? options.capacity : undefined, @@ -9844,13 +11646,29 @@ export const toQueue: { ) /** + * 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 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: { @@ -9863,8 +11681,16 @@ export const toQueueArray: { 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>, @@ -9888,12 +11714,28 @@ export const toQueueArray: { ) { const scope = yield* Effect.scope const queue = yield* Queue.make({ capacity: typeof options.capacity === "number" ? options.capacity : undefined, @@ -9908,21 +11750,25 @@ export 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 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: { @@ -9941,11 +11787,13 @@ export 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, @@ -9978,11 +11826,13 @@ export const toPubSub: { const pubsub = yield* makePubSub(options) yield* Effect.forkScoped(runIntoPubSub(self, pubsub, { @@ -9993,13 +11843,27 @@ export const toPubSub: { ) /** + * 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 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, @@ -10010,8 +11874,15 @@ export const runIntoPubSub: { 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, @@ -10056,23 +11927,31 @@ const makePubSub = ( ) /** - * 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 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: { @@ -10089,13 +11968,17 @@ export const toPubSubArray: { 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>, @@ -10126,13 +12009,17 @@ export const toPubSubArray: { } ) { const pubsub = yield* makePubSub(options) yield* Effect.forkScoped(runIntoPubSubArray(self, pubsub, { @@ -10143,13 +12030,31 @@ export const toPubSubArray: { ) /** + * 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 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, @@ -10160,8 +12065,17 @@ export const runIntoPubSubArray: { 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>, @@ -10185,17 +12099,29 @@ export const runIntoPubSubArray: { ) /** - * 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 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: { @@ -10214,10 +12140,16 @@ export const toPubSubTake: { 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>, @@ -10248,10 +12180,16 @@ export const toPubSubTake: { } ) { const pubsub = yield* makePubSub>(options) yield* runForEach(self, (value) => PubSub.publish(pubsub, value)).pipe(