/** * Provides low-level building blocks for streaming data through Effect. * * 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. * * @stability stable * @since 2.0.0 */ import * as Arr from "./Array.ts"; import * as Cause from "./Cause.ts"; import * as Chunk from "./Chunk.ts"; import * as Context from "./Context.ts"; import * as Effect from "./Effect.ts"; import * as Exit from "./Exit.ts"; import type * as Filter from "./Filter.ts"; import type { LazyArg } from "./Function.ts"; import * as Layer from "./Layer.ts"; import type { Severity } from "./LogLevel.ts"; import * as Option from "./Option.ts"; import type { Pipeable } from "./Pipeable.ts"; import type * as Predicate from "./Predicate.ts"; import * as PubSub from "./PubSub.ts"; import * as Pull from "./Pull.ts"; import * as Queue from "./Queue.ts"; import * as Schedule from "./Schedule.ts"; import * as Scope from "./Scope.ts"; import * as Take from "./Take.ts"; import { ParentSpan, type SpanOptions } from "./Tracer.ts"; import type * as Types from "./Types.ts"; import type * as Unify from "./Unify.ts"; /** * String literal type used as the unique brand for `Channel` values. * * @stability stable * @category type IDs * @since 4.0.0 */ export type TypeId = "~effect/Channel"; /** * Runtime identifier stored on `Channel` values and used by `isChannel` to * recognize them. * * @stability stable * @category type IDs * @since 4.0.0 */ export declare const TypeId: TypeId; /** * Checks whether a value is a `Channel`. * * **Example** (Checking for channels) * * ```ts import.meta.vitest * import { Channel } from "effect" * * const channel = Channel.succeed(42) * Channel.isChannel(channel) // => true * Channel.isChannel("not a channel") // => false * ``` * * @stability stable * @category guards * @since 3.5.4 */ export declare const isChannel: (u: unknown) => u is Channel; /** * A `Channel` is a nexus of I/O operations, which supports both reading and * writing. A channel may read values of type `InElem` and write values of type * `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 * adding new stream and sink operators, or doing something highly specialized, * it may be useful to use channels directly. * * Channels compose in a variety of ways: * * - **Piping**: One channel can be piped to another channel, assuming the * input type of the second is the same as the output type of the first. * - **Sequencing**: The terminal value of one channel can be used to create * another channel, and both the first channel and the function that makes * the second channel can be composed into a channel. * - **Concatenating**: The output of one channel can be used to create other * channels, which are all concatenated together. The first channel and the * function that makes the other channels can be composed into a channel. * * **Example** (Typing channels) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // A channel that outputs numbers and requires no environment * type NumberChannel = Channel.Channel * * // A channel that outputs strings, can fail with Error, completes with boolean * type StringChannel = Channel.Channel * * // A channel with all type parameters specified * type FullChannel = Channel.Channel< * string, // OutElem - output elements * Error, // OutErr - output errors * number, // OutDone - completion value * number, // InElem - input elements * string, // InErr - input errors * boolean, // InDone - input completion * { db: string } // Env - required environment * > * * const channel: NumberChannel = Channel.succeed(1) * Effect.runSync(Channel.runCollect(channel)) // => [1] * ``` * * @stability stable * @category models * @since 2.0.0 */ export interface Channel extends Variance, Pipeable { [Unify.typeSymbol]?: unknown; [Unify.unifySymbol]?: ChannelUnify; [Unify.ignoreSymbol]?: ChannelUnifyIgnore; } /** * 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. * * @stability stable * @category models * @since 2.0.0 */ export interface ChannelUnify extends Effect.EffectUnify { Channel?: () => A[Unify.typeSymbol] extends Channel | infer _ ? Channel : never; } /** * Marker used by `Unify` while resolving `Channel` values. * * **Details** * * It prevents the inherited `Effect` unifier from being selected when the * channel-specific unifier should preserve `Channel` input, output, and * environment type parameters. Users normally do not need to reference this * interface directly. * * @stability stable * @category models * @since 2.0.0 */ export interface ChannelUnifyIgnore { Effect?: true; } type TagsWithReason = { [T in Types.Tags]: Types.ReasonTags> extends never ? never : T; }[Types.Tags]; /** * 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. * * @stability stable * @category models * @since 2.0.0 */ export interface Variance { readonly [TypeId]: VarianceStruct; } /** * 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. * * @stability stable * @category models * @since 2.0.0 */ export interface VarianceStruct { _Env: Types.Covariant; _InErr: Types.Contravariant; _InElem: Types.Contravariant; _InDone: Types.Contravariant; _OutErr: Types.Covariant; _OutElem: Types.Covariant; _OutDone: Types.Covariant; } /** * Creates a `Channel` from a transformation function that operates on upstream pulls. * * **Example** (Creating channels from transforms) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const channel = Channel.fromTransform((upstream, scope) => * Effect.succeed(upstream) * ) * await Effect.runPromise(Channel.runCollect(channel)) // => [] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromTransform: (transform: (upstream: Pull.Pull, scope: Scope.Scope) => Effect.Effect, EX, Env>) => Channel | EX, OutDone, InElem, InErr, InDone, Env | EnvX>; /** * Transforms a Channel by applying a function to its Pull implementation. * * **Example** (Transforming pull behavior) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // Transform a channel by modifying its pull behavior * const originalChannel = Channel.fromIterable([1, 2, 3]) * * const transformedChannel = Channel.transformPull( * originalChannel, * (pull, scope) => * Effect.succeed( * Effect.map(pull, (value) => value * 2) * ) * ) * await Effect.runPromise(Channel.runCollect(transformedChannel)) // => [2, 4, 6] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const transformPull: (self: Channel, f: (pull: Pull.Pull, scope: Scope.Scope) => Effect.Effect, OutErrX, EnvX>) => Channel | OutErrX, OutDone2, InElem, InErr, InDone, Env | Env2 | EnvX>; /** * Creates a `Channel` from an `Effect` that produces a `Pull`. * * **Example** (Creating channels from pulls) * * ```ts import.meta.vitest * import { Cause, Channel, Effect } from "effect" * * const channel = Channel.fromPull(Effect.sync(() => { * let emitted = false * return Effect.suspend(() => { * if (emitted) return Cause.done() * emitted = true * return Effect.succeed(42) * }) * })) * await Effect.runPromise(Channel.runCollect(channel)) // => [42] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromPull: (effect: Effect.Effect, EX, Env>) => Channel | EX, OutDone, unknown, unknown, unknown, Env | EnvX>; /** * Creates a `Channel` from a transformation function that operates on upstream * pulls, but also provides a forked scope that closes when the resulting * Channel completes. * * **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 * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromTransformBracket: (f: (upstream: Pull.Pull, scope: Scope.Scope, forkedScope: Scope.Scope) => Effect.Effect, EX, Env>) => Channel | EX, OutDone, InElem, InErr, InDone, Env | EnvX>; /** * Converts a `Channel` back to its underlying transformation function. * * **Example** (Extracting channel transforms) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const channel = Channel.succeed(42) * const transform = Channel.toTransform(channel) * typeof transform // => "function" * Effect.runSync(Channel.runCollect(channel)) // => [42] * ``` * * @stability stable * @category destructors * @since 4.0.0 */ export declare const toTransform: (channel: Channel) => (upstream: Pull.Pull, scope: Scope.Scope) => Effect.Effect, never, Env>; /** * The default chunk size used by channels for batching operations. * * **Example** (Reading the default chunk size) * * ```ts import.meta.vitest * import { Channel } from "effect" * * Channel.DefaultChunkSize // => 4096 * ``` * * @stability stable * @category constants * @since 4.0.0 */ export declare const DefaultChunkSize: number; /** * Creates a `Channel` that interacts with a callback function using a queue. * * **Example** (Creating channels from callbacks) * * ```ts import.meta.vitest * import { Channel, Effect, Queue } from "effect" * * const channel = Channel.callback((queue) => * Effect.gen(function*() { * yield* Queue.offer(queue, 1) * yield* Queue.offer(queue, 2) * yield* Queue.offer(queue, 3) * yield* Queue.end(queue) * }) * ) * await Effect.runPromise(Channel.runCollect(channel)) // => [1, 2, 3] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const callback: (f: (queue: Queue.Queue) => Effect.Effect, options?: { readonly bufferSize?: number | undefined; readonly strategy?: "sliding" | "dropping" | "suspend" | undefined; }) => Channel>; /** * Creates a `Channel` that interacts with a callback function using a queue, emitting arrays. * * **Example** (Creating array channels from callbacks) * * ```ts import.meta.vitest * import { Channel, Effect, Queue } from "effect" * * const channel = Channel.callbackArray(Effect.fn(function*(queue) { * yield* Queue.offer(queue, 1) * yield* Queue.offer(queue, 2) * yield* Queue.end(queue) * })) * await Effect.runPromise(Channel.runCollect(channel)) // => [[1, 2]] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const callbackArray: (f: (queue: Queue.Queue) => Effect.Effect, options?: { readonly bufferSize?: number | undefined; readonly strategy?: "sliding" | "dropping" | "suspend" | undefined; }) => Channel, E, void, unknown, unknown, unknown, Exclude>; /** * Creates a `Channel` that lazily evaluates to another channel. * * **Example** (Suspending channel creation) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const channel = Channel.suspend(() => Channel.succeed(42)) * Effect.runSync(Channel.runCollect(channel)) // => [42] * ``` * * @stability stable * @category constructors * @since 2.0.0 */ export declare const suspend: (evaluate: LazyArg>) => Channel; /** * 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) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const released: Array = [] * const channel = Channel.acquireUseRelease( * Effect.succeed("resource"), * (resource) => Channel.succeed(resource.toUpperCase()), * (resource, exit) => Effect.sync(() => released.push(resource)) * ) * const observed = [await Effect.runPromise(Channel.runCollect(channel)), released] // => [["RESOURCE"], ["resource"]] * ``` * * @stability stable * @category constructors * @since 2.0.0 */ export declare const acquireUseRelease: (acquire: Effect.Effect, use: (a: A) => Channel, release: (a: A, exit: Exit.Exit) => Effect.Effect) => Channel; /** * 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) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const released: Array = [] * const channel = Channel.acquireRelease( * Effect.succeed("resource"), * (resource, exit) => Effect.sync(() => released.push(resource)) * ) * const observed = [await Effect.runPromise(Channel.runCollect(channel)), released] // => [["resource"], ["resource"]] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const acquireRelease: { /** * 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) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const released: Array = [] * const channel = Channel.acquireRelease( * Effect.succeed("resource"), * (resource, exit) => Effect.sync(() => released.push(resource)) * ) * const observed = [await Effect.runPromise(Channel.runCollect(channel)), released] // => [["resource"], ["resource"]] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ (release: (z: Z, e: Exit.Exit) => Effect.Effect): (self: Effect.Effect) => Channel; /** * 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) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const released: Array = [] * const channel = Channel.acquireRelease( * Effect.succeed("resource"), * (resource, exit) => Effect.sync(() => released.push(resource)) * ) * const observed = [await Effect.runPromise(Channel.runCollect(channel)), released] // => [["resource"], ["resource"]] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ (self: Effect.Effect, release: (z: Z, e: Exit.Exit) => Effect.Effect): Channel; }; /** * Creates a `Channel` from an iterator. * * **Example** (Creating channels from iterators) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const numbers = [1, 2, 3, 4, 5] * const channel = Channel.fromIterator(() => numbers[Symbol.iterator]()) * Effect.runSync(Channel.runCollect(channel)) // => [1, 2, 3, 4, 5] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromIterator: (iterator: LazyArg>) => Channel; /** * Creates a `Channel` that emits all elements from an array. * * **Example** (Creating channels from arrays) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const channel = Channel.fromArray([1, 2, 3, 4, 5]) * Effect.runSync(Channel.runCollect(channel)) // => [1, 2, 3, 4, 5] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromArray: (array: ReadonlyArray) => Channel; /** * Creates a `Channel` that emits all elements from a chunk. * * **Example** (Creating channels from chunks) * * ```ts import.meta.vitest * import { Channel, Chunk, Effect } from "effect" * * const chunk = Chunk.make(1, 2, 3) * const channel = Channel.fromChunk(chunk) * Effect.runSync(Channel.runCollect(channel)) // => [1, 2, 3] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromChunk: (chunk: Chunk.Chunk) => Channel; /** * Creates a `Channel` from an iterator that emits arrays of elements. * * **Details** * * Finite fractional `chunkSize` values are rounded down. `NaN` and non-positive * values are treated as `1` so every successful pull emits a non-empty array. * * **Example** (Batching iterator output) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // Create a channel from a simple iterator * const numberIterator = (): Iterator => { * let count = 0 * return { * next: () => { * if (count < 3) { * return { value: count++, done: false } * } * return { value: "finished", done: true } * } * } * } * * const channel = Channel.fromIteratorArray(() => numberIterator(), 2) * Effect.runSync(Channel.runCollect(channel)) // => [[0, 1], [2]] * ``` * * **Example** (Batching generator output) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // Create channel from a generator function * function* fibonacci(): Generator { * let a = 0, b = 1 * for (let i = 0; i < 5; i++) { * yield a * ;[a, b] = [b, a + b] * } * } * * const fibChannel = Channel.fromIteratorArray(() => fibonacci(), 3) * Effect.runSync(Channel.runCollect(fibChannel)) // => [[0, 1, 1], [2, 3]] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromIteratorArray: (iterator: LazyArg>, chunkSize?: number) => Channel, never, L>; /** * Creates a `Channel` that emits all elements from an iterable. * * **Example** (Creating channels from iterables) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const set = new Set([1, 2, 3]) * const channel = Channel.fromIterable(set) * Effect.runSync(Channel.runCollect(channel)) // => [1, 2, 3] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromIterable: (iterable: Iterable) => Channel; /** * Creates a `Channel` that emits arrays of elements from an iterable. * * **Details** * * Finite fractional `chunkSize` values are rounded down. `NaN` and non-positive * values are treated as `1`. * * **Example** (Batching iterable output) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const numbers = [1, 2, 3, 4, 5] * const channel = Channel.fromIterableArray(numbers, 4) * Effect.runSync(Channel.runCollect(channel)) // => [[1, 2, 3, 4], [5]] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromIterableArray: (iterable: Iterable, chunkSize?: number) => Channel, never, L>; /** * Creates a `Channel` that emits a single value and then ends. * * **Example** (Creating channels that succeed) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const channel = Channel.succeed(42) * Effect.runSync(Channel.runCollect(channel)) // => [42] * ``` * * @stability stable * @category constructors * @since 2.0.0 */ export declare const succeed: (value: A) => Channel; /** * Creates a `Channel` that immediately ends with the specified value. * * **Example** (Ending with a value) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const channel = Channel.end("done") * Effect.runSync(Channel.runCollect(channel)) // => [] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const end: (value: A) => Channel; /** * Creates a `Channel` that immediately ends with the lazily evaluated value. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const endSync: (evaluate: LazyArg) => Channel; /** * Creates a `Channel` that emits a single value computed by a lazy evaluation. * * **Example** (Computing values lazily) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * let requests = 0 * * const channel = Channel.sync(() => { * requests += 1 * return `request-${requests}` * }) * Effect.runSync(Channel.runCollect(channel)) // => ["request-1"] * ``` * * @stability stable * @category constructors * @since 2.0.0 */ export declare const sync: (evaluate: LazyArg) => Channel; /** * Represents a `Channel` that emits no elements. * * **Example** (Creating empty channels) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // Create an empty channel * const emptyChannel = Channel.empty * * // Use empty channel in composition * const combined = Channel.concatWith(emptyChannel, () => Channel.succeed(42)) * // Will immediately provide the second channel's output * * // Empty channel can be used as a no-op in conditional logic * const conditionalChannel = (shouldEmit: boolean) => * shouldEmit ? Channel.succeed("data") : Channel.empty * * Effect.runSync(Channel.runCollect(conditionalChannel(true))) // => ["data"] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const empty: Channel; /** * Represents a `Channel` that never completes. * * **Example** (Creating non-terminating channels) * * ```ts import.meta.vitest * import { Channel } from "effect" * * // Create a channel that never completes * const neverChannel = Channel.never * * // Use in conditional logic * const withFallback = Channel.concatWith( * neverChannel, * () => Channel.succeed("fallback") * ) * * // Never channel is useful for testing or as a placeholder * const conditionalChannel = (shouldComplete: boolean) => * shouldComplete ? Channel.succeed("done") : Channel.never * * Channel.isChannel(conditionalChannel(false)) // => true * ``` * * @stability stable * @category constructors * @since 2.0.0 */ export declare const never: Channel; /** * Constructs a channel that fails immediately with the specified error. * * **Example** (Failing with an error) * * ```ts import.meta.vitest * import { Channel, Effect, Exit } from "effect" * * const failedChannel = Channel.fail("Something went wrong") * Effect.runSync(Effect.exit(Channel.runCollect(failedChannel))) // => Exit.fail("Something went wrong") * ``` * * @stability stable * @category constructors * @since 2.0.0 */ export declare const fail: (error: E) => Channel; /** * Constructs a channel that fails immediately with the specified lazily * evaluated error. * * **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.meta.vitest * import { Channel, Effect, Exit } from "effect" * * let attempts = 0 * const conditionalError = Channel.failSync(() => { * attempts += 1 * return `Error after attempt ${attempts}` * }) * const observed = [ * Effect.runSync(Effect.exit(Channel.runCollect(conditionalError))), * attempts * ] // => [Exit.fail("Error after attempt 1"), 1] * ``` * * @stability stable * @category constructors * @since 2.0.0 */ export declare const failSync: (evaluate: LazyArg) => Channel; /** * Constructs a channel that fails immediately with the specified `Cause`. * * **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.meta.vitest * import { Cause, Channel, Effect, Exit } from "effect" * * const simpleCause = Cause.fail("Simple error") * const failedChannel = Channel.failCause(simpleCause) * Effect.runSync(Effect.exit(Channel.runCollect(failedChannel))) // => Exit.failCause(simpleCause) * ``` * * @stability stable * @category constructors * @since 2.0.0 */ export declare const failCause: (cause: Cause.Cause) => Channel; /** * Constructs a channel that fails immediately with the specified lazily * evaluated `Cause`. * * **Example** (Failing with lazy causes) * * ```ts import.meta.vitest * import { Cause, Channel, Effect, Exit } from "effect" * * // Create a channel that fails with a lazily computed cause * let attempts = 0 * const failedChannel = Channel.failCauseSync(() => { * attempts += 1 * return Cause.fail(`Runtime error after attempt ${attempts}`) * }) * * const observed = [ * Effect.runSync(Effect.exit(Channel.runCollect(failedChannel))), * attempts * ] // => [Exit.fail("Runtime error after attempt 1"), 1] * ``` * * @stability stable * @category constructors * @since 2.0.0 */ export declare const failCauseSync: (evaluate: LazyArg>) => Channel; /** * Constructs a channel that fails immediately with the specified defect. * * **Example** (Dying with defects) * * ```ts import.meta.vitest * import { Cause, Channel, Effect, Exit } from "effect" * * const defect = "Unrecoverable error" * const diedChannel = Channel.die(defect) * Effect.runSync(Effect.exit(Channel.runCollect(diedChannel))) // => Exit.failCause(Cause.die(defect)) * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const die: (defect: unknown) => Channel; /** * Uses an effect to write a single value to the channel. * * **Example** (Creating channels from effects) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const successChannel = Channel.fromEffect( * Effect.succeed("Hello from effect!") * ) * Effect.runSync(Channel.runCollect(successChannel)) // => ["Hello from effect!"] * ``` * * @stability stable * @category constructors * @since 2.0.0 */ export declare const fromEffect: (effect: Effect.Effect) => Channel, void, unknown, unknown, unknown, R>; /** * 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. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromEffectDone: (effect: Effect.Effect) => Channel, A, unknown, unknown, unknown, R>; /** * Uses an effect and discards its result. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromEffectDrain: (effect: Effect.Effect) => Channel; /** * 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. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromEffectTake: (effect: Effect.Effect, E2, R>) => Channel, E | E2, Done, unknown, unknown, unknown, R>; /** * Creates a channel from a queue. * * **Example** (Creating channels from queues) * * ```ts import.meta.vitest * import { Cause, Channel, Effect, Queue } from "effect" * * const program = Effect.gen(function*() { * const queue = yield* Queue.bounded(3) * yield* Queue.offerAll(queue, ["item1", "item2", "item3"]) * yield* Queue.end(queue) * const channel = Channel.fromQueue(queue) * return yield* Channel.runCollect(channel) * }) * await Effect.runPromise(program) // => ["item1", "item2", "item3"] * ``` * * @stability stable * @category constructors * @since 2.0.0 */ export declare const fromQueue: (queue: Queue.Dequeue) => Channel>; /** * Creates a channel from a queue that emits arrays of elements. * * **Example** (Creating batched channels from queues) * * ```ts import.meta.vitest * import { Cause, Channel, Effect, Queue } from "effect" * * const program = Effect.gen(function*() { * const queue = yield* Queue.bounded(4) * yield* Queue.offerAll(queue, [1, 2, 3, 4]) * yield* Queue.end(queue) * const arrayChannel = Channel.fromQueueArray(queue) * return yield* Channel.runCollect(arrayChannel) * }) * await Effect.runPromise(program) // => [[1, 2, 3, 4]] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromQueueArray: (queue: Queue.Dequeue) => Channel, Exclude>; /** * Creates a channel that forwards upstream input elements, input errors, and * the upstream done value unchanged. * * @stability stable * @category constructors * @since 2.0.0 */ export declare const identity: () => Channel; /** * Creates a channel from a PubSub subscription. * * **Example** (Creating channels from subscriptions) * * ```ts import.meta.vitest * import { Channel, Data, Effect, Option, PubSub } from "effect" * * class SubscriptionError extends Data.TaggedError("SubscriptionError")<{ * readonly reason: string * }> {} * * const program = Effect.gen(function*() { * // Create a PubSub * const pubsub = yield* PubSub.bounded(32) * * // Create a subscription * const subscription = yield* PubSub.subscribe(pubsub) * * // Publish some messages * yield* PubSub.publish(pubsub, "Hello") * yield* PubSub.publish(pubsub, "World") * yield* PubSub.publish(pubsub, "from") * yield* PubSub.publish(pubsub, "PubSub") * * // Create a channel from the subscription * const channel = Channel.fromSubscription(subscription) * * // The channel will receive all published messages * return channel * }) * const result = Effect.scoped(Effect.flatMap(program, Channel.runHead)) * await Effect.runPromise(result) // => Option.some("Hello") * * // Real-time notifications example * const notificationChannel = Effect.gen(function*() { * const eventBus = yield* PubSub.unbounded<{ type: string; payload: any }>() * const userSubscription = yield* PubSub.subscribe(eventBus) * * return Channel.fromSubscription(userSubscription) * }) * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromSubscription: (subscription: PubSub.Subscription) => Channel; /** * 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. * * **Example** (Batching subscription values) * * ```ts import.meta.vitest * import { Channel, Data, Effect, Option, PubSub } from "effect" * * class StreamError extends Data.TaggedError("StreamError")<{ * readonly message: string * }> {} * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.bounded(16) * const subscription = yield* PubSub.subscribe(pubsub) * * // Create a channel that reads arrays of values * const channel = Channel.fromSubscriptionArray(subscription) * * // Publish some values * yield* PubSub.publish(pubsub, 1) * yield* PubSub.publish(pubsub, 2) * yield* PubSub.publish(pubsub, 3) * yield* PubSub.publish(pubsub, 4) * * // The channel will output arrays like [1, 2, 3] and [4] * return channel * }) * const result = Effect.scoped(Effect.flatMap(program, Channel.runHead)) * await Effect.runPromise(result) // => Option.some([1, 2, 3, 4]) * ``` * * **Example** (Processing subscription values in batches) * * ```ts import.meta.vitest * import { Channel, Data, Effect, Option, PubSub } from "effect" * * class BatchProcessingError extends Data.TaggedError("BatchProcessingError")<{ * readonly reason: string * }> {} * * const batchProcessor = Effect.gen(function*() { * const pubsub = yield* PubSub.bounded(32) * const subscription = yield* PubSub.subscribe(pubsub) * * // Create a channel that processes items in batches * const batchChannel = Channel.fromSubscriptionArray(subscription) * * // Transform to process each batch * const processedChannel = Channel.map(batchChannel, (batch) => * batch.map((item) => item.toUpperCase()) * ) * * yield* PubSub.publishAll(pubsub, ["one", "two"]) * return processedChannel * }) * const batch = Effect.scoped(Effect.flatMap(batchProcessor, Channel.runHead)) * await Effect.runPromise(batch) // => Option.some(["ONE", "TWO"]) * ``` * * **Example** (Aggregating subscription metrics) * * ```ts import.meta.vitest * import { Channel, Effect, Option, PubSub } from "effect" * * const metricsAggregator = Effect.gen(function*() { * const metricsPubSub = yield* PubSub.bounded< * { timestamp: number; value: number } * >(100) * const subscription = yield* PubSub.subscribe(metricsPubSub) * * // Create a channel that collects metrics in chunks * const metricsChannel = Channel.fromSubscriptionArray(subscription) * * // Transform to calculate aggregate statistics * const aggregatedChannel = Channel.map(metricsChannel, (metrics) => { * const values = metrics.map((m) => m.value) * const sum = values.reduce((a, b) => a + b, 0) * const avg = sum / values.length * const min = Math.min(...values) * const max = Math.max(...values) * * return { * count: values.length, * sum, * average: avg, * min, * max, * firstTimestamp: Math.min(...metrics.map((m) => m.timestamp)), * lastTimestamp: Math.max(...metrics.map((m) => m.timestamp)) * } * }) * * yield* PubSub.publish(metricsPubSub, { timestamp: 1, value: 10 }) * return aggregatedChannel * }) * const metric = Effect.scoped(Effect.flatMap(metricsAggregator, Channel.runHead)) * const result = await Effect.runPromise(metric) * Option.map(result, ({ count, sum, average, min, max }) => ({ count, sum, average, min, max })) // => Option.some({ count: 1, sum: 10, average: 10, min: 10, max: 10 }) * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromSubscriptionArray: (subscription: PubSub.Subscription) => Channel>; /** * 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. * * **Example** (Creating channels from PubSubs) * * ```ts import.meta.vitest * import { Channel, Data, Effect, Option, PubSub } from "effect" * * class StreamError extends Data.TaggedError("StreamError")<{ * readonly message: string * }> {} * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.unbounded({ replay: 3 }) * * // Create a channel that reads individual values * const channel = Channel.fromPubSub(pubsub) * * // Publish some values * yield* PubSub.publish(pubsub, 1) * yield* PubSub.publish(pubsub, 2) * yield* PubSub.publish(pubsub, 3) * * // The channel will output: 1, 2, 3 (individual values) * return channel * }) * const result = Effect.scoped(Effect.flatMap(program, Channel.runHead)) * await Effect.runPromise(result) // => Option.some(1) * ``` * * **Example** (Streaming PubSub notifications) * * ```ts import.meta.vitest * import { Channel, Effect, Option, PubSub } from "effect" * * const notificationService = Effect.gen(function*() { * const notificationPubSub = yield* PubSub.unbounded({ replay: 1 }) * * // Create a channel for real-time notifications * 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, * receivedAt, * id: `notification:${message}` * })) * * yield* PubSub.publish(notificationPubSub, "ready") * return timestampedChannel * }) * const notification = Effect.scoped(Effect.flatMap(notificationService, Channel.runHead)) * await Effect.runPromise(notification) // => Option.some({ message: "ready", receivedAt: "2024-01-01T00:00:00.000Z", id: "notification:ready" }) * ``` * * **Example** (Processing PubSub events) * * ```ts import.meta.vitest * import { Channel, Effect, Option, PubSub } from "effect" * * interface DomainEvent { * readonly type: string * readonly payload: unknown * readonly timestamp: number * } * * const eventProcessor = Effect.gen(function*() { * const eventPubSub = yield* PubSub.unbounded({ replay: 1 }) * * // Create a channel for processing domain events * const eventChannel = Channel.fromPubSub(eventPubSub) * * // Filter and transform events * const processedChannel = Channel.map(eventChannel, (event) => { * if (event.type === "user.created") { * return { * ...event, * processed: true, * processedAt: event.timestamp + 1 * } * } * return event * }) * * yield* PubSub.publish(eventPubSub, { type: "user.created", payload: {}, timestamp: 1 }) * return processedChannel * }) * const event = Effect.scoped(Effect.flatMap(eventProcessor, Channel.runHead)) * const result = await Effect.runPromise(event) // => Option.some({ type: "user.created", payload: {}, timestamp: 1, processed: true, processedAt: 2 }) * ``` * * @stability stable * @category constructors * @since 2.0.0 */ export declare const fromPubSub: (pubsub: PubSub.PubSub) => Channel; /** * 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. * * **Example** (Batching PubSub values) * * ```ts import.meta.vitest * import { Channel, Data, Effect, Option, PubSub } from "effect" * * class BatchError extends Data.TaggedError("BatchError")<{ * readonly message: string * }> {} * * const program = Effect.gen(function*() { * const pubsub = yield* PubSub.unbounded({ replay: 4 }) * * // Create a channel that reads arrays of values * const channel = Channel.fromPubSubArray(pubsub) * * // Publish some values * yield* PubSub.publish(pubsub, 1) * yield* PubSub.publish(pubsub, 2) * yield* PubSub.publish(pubsub, 3) * yield* PubSub.publish(pubsub, 4) * * // The channel will output arrays like [1, 2, 3] and [4] * return channel * }) * const result = Effect.scoped(Effect.flatMap(program, Channel.runHead)) * await Effect.runPromise(result) // => Option.some([1, 2, 3, 4]) * ``` * * **Example** (Processing PubSub orders in batches) * * ```ts import.meta.vitest * import { Channel, Effect, Option, 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*() { * const orderPubSub = yield* PubSub.unbounded({ replay: 1 }) * * // Create a channel that processes orders in batches * const orderChannel = Channel.fromPubSubArray(orderPubSub) * * // Transform to process each batch of orders * const processedChannel = Channel.map(orderChannel, (orderBatch) => { * const totalRevenue = orderBatch.reduce((sum, order) => sum + order.total, 0) * const customerCount = new Set(orderBatch.map((order) => * order.customerId * )).size * * return { * batchSize: orderBatch.length, * totalRevenue, * uniqueCustomers: customerCount, * firstSubmittedAt: Math.min(...orderBatch.map((order) => order.submittedAt)), * orders: orderBatch * } * }) * * yield* PubSub.publish(orderPubSub, { * id: "1", customerId: "a", items: ["book"], total: 10, submittedAt: 1 * }) * return processedChannel * }) * const order = Effect.scoped(Effect.flatMap(orderBatchProcessor, Channel.runHead)) * const result = await Effect.runPromise(order) * Option.map(result, (batch) => [batch.batchSize, batch.totalRevenue, batch.uniqueCustomers]) // => Option.some([1, 10, 1]) * ``` * * **Example** (Processing PubSub logs in batches) * * ```ts import.meta.vitest * import { Channel, Effect, Option, PubSub } from "effect" * * interface LogEntry { * readonly timestamp: number * readonly level: "info" | "warn" | "error" * readonly message: string * readonly source: string * } * * const logAggregator = Effect.gen(function*() { * const logPubSub = yield* PubSub.unbounded({ replay: 1 }) * * // Create a channel that collects logs in batches * const logChannel = Channel.fromPubSubArray(logPubSub) * * // Transform to analyze log batches * const analysisChannel = Channel.map(logChannel, (logBatch) => { * const errorCount = logBatch.filter((log) => log.level === "error").length * const warnCount = logBatch.filter((log) => log.level === "warn").length * const infoCount = logBatch.filter((log) => log.level === "info").length * * const timeRange = { * start: Math.min(...logBatch.map((log) => log.timestamp)), * end: Math.max(...logBatch.map((log) => log.timestamp)) * } * * return { * batchId: `${timeRange.start}-${timeRange.end}`, * totalEntries: logBatch.length, * errorCount, * warnCount, * infoCount, * timeRange, * sources: [...new Set(logBatch.map((log) => log.source))] * } * }) * * yield* PubSub.publish(logPubSub, { * timestamp: 1, * level: "info", * message: "ready", * source: "app" * } satisfies LogEntry) * return analysisChannel * }) * const log = Effect.scoped(Effect.flatMap(logAggregator, Channel.runHead)) * const result = await Effect.runPromise(log) * Option.map(result, (batch) => [batch.batchId, batch.totalEntries, batch.infoCount]) // => Option.some(["1-1", 1, 1]) * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromPubSubArray: (pubsub: PubSub.PubSub) => Channel>; /** * 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. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromPubSubTake: (pubsub: PubSub.PubSub>) => Channel, E, Done>; /** * Creates a Channel from a Schedule. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromSchedule: (schedule: Schedule.Schedule) => Channel; /** * Creates a channel from a lazily supplied Web `ReadableStream`. * * **Details** * * Read failures are mapped with `onError`. Finalization cancels the reader and * releases its lock, or only releases the lock when `releaseLockOnEnd` is set. * A rejected cancel hook becomes a defect. * * **Example** (Reading from a Web stream) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const channel = Channel.fromReadableStream({ * evaluate: () => new ReadableStream({ * start(controller) { * controller.enqueue(1) * controller.close() * } * }), * onError: (cause) => new Error(String(cause)) * }) * * await Effect.runPromise(Channel.runCollect(channel)) // => [[1]] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromReadableStream: (options: { readonly evaluate: LazyArg>; readonly onError: (error: unknown) => E; readonly releaseLockOnEnd?: boolean | undefined; }) => Channel, E>; /** * Creates a channel that writes upstream values to a lazily supplied Web * `WritableStream`. * * **Example** (Writing channel input) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const written: Array = [] * const sink = Channel.fromWritableStream({ * evaluate: () => new WritableStream({ * write(value) { * written.push(value) * } * }), * onError: (cause) => new Error(String(cause)) * }) * * const program = Channel.fromArray([[1, 2] as [number, number]]).pipe( * Channel.pipeTo(sink), * Channel.runDrain * ) * * await Effect.runPromise(program) * written // => [1, 2] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromWritableStream: (options: { readonly evaluate: LazyArg>; readonly onError: (error: unknown) => E; readonly closeOnDone?: boolean | undefined; }) => Channel, IE>; /** * Creates a channel backed by a Web `TransformStream`, writing upstream values * while emitting transformed values from its readable side. * * **Example** (Transforming channel input) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const transform = Channel.fromTransformStream({ * evaluate: () => new TransformStream({ * transform(value, controller) { * controller.enqueue(value * 2) * } * }), * onError: (cause) => new Error(String(cause)) * }) * * const program = Channel.fromArray([[1, 2] as [number, number]]).pipe( * Channel.pipeTo(transform), * Channel.runCollect * ) * * await Effect.runPromise(program) // => [[2], [4]] * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromTransformStream: (options: { readonly evaluate: LazyArg>; readonly onError: (error: unknown) => E; readonly closeOnDone?: boolean | undefined; readonly releaseLockOnEnd?: boolean | undefined; }) => Channel, IE | E, void, Arr.NonEmptyReadonlyArray, IE>; /** * 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. It is awaited unless * a `next()` call is still pending, in which case its result is ignored and an * async generator may not run its cleanup until that pull settles. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromAsyncIterable: (iterable: AsyncIterable, onError: (error: unknown) => E) => Channel; /** * 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. * It is awaited unless a `next()` call is still pending, in which case its * result is ignored and an async generator may not run its cleanup until that * pull settles. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const fromAsyncIterableArray: (iterable: AsyncIterable, onError: (error: unknown) => E) => Channel, E, D>; /** * Maps the output of this channel using the specified function. * * **Example** (Mapping channel output) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class TransformError extends Data.TaggedError("TransformError")<{ * readonly reason: string * }> {} * * // Basic mapping of channel values * const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5]) * const doubledChannel = Channel.map(numbersChannel, (n) => n * 2) * Effect.runSync(Channel.runCollect(doubledChannel)) // => [2, 4, 6, 8, 10] * * // Transform string data * const wordsChannel = Channel.fromIterable(["hello", "world", "effect"]) * const upperCaseChannel = Channel.map(wordsChannel, (word) => word.toUpperCase()) * Effect.runSync(Channel.runCollect(upperCaseChannel)) // => ["HELLO", "WORLD", "EFFECT"] * * // Complex object transformation * type User = { id: number; name: string } * type UserDisplay = { displayName: string; isActive: boolean } * * const usersChannel = Channel.fromIterable([ * { id: 1, name: "Alice" }, * { id: 2, name: "Bob" } * ]) * const displayChannel = Channel.map(usersChannel, (user): UserDisplay => ({ * displayName: `User: ${user.name}`, * isActive: true * })) * Effect.runSync(Channel.runCollect(displayChannel)) // => [{ displayName: "User: Alice", isActive: true }, { displayName: "User: Bob", isActive: true }] * ``` * * @stability stable * @category sequencing * @since 2.0.0 */ export declare const map: { /** * Maps the output of this channel using the specified function. * * **Example** (Mapping channel output) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class TransformError extends Data.TaggedError("TransformError")<{ * readonly reason: string * }> {} * * // Basic mapping of channel values * const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5]) * const doubledChannel = Channel.map(numbersChannel, (n) => n * 2) * Effect.runSync(Channel.runCollect(doubledChannel)) // => [2, 4, 6, 8, 10] * * // Transform string data * const wordsChannel = Channel.fromIterable(["hello", "world", "effect"]) * const upperCaseChannel = Channel.map(wordsChannel, (word) => word.toUpperCase()) * Effect.runSync(Channel.runCollect(upperCaseChannel)) // => ["HELLO", "WORLD", "EFFECT"] * * // Complex object transformation * type User = { id: number; name: string } * type UserDisplay = { displayName: string; isActive: boolean } * * const usersChannel = Channel.fromIterable([ * { id: 1, name: "Alice" }, * { id: 2, name: "Bob" } * ]) * const displayChannel = Channel.map(usersChannel, (user): UserDisplay => ({ * displayName: `User: ${user.name}`, * isActive: true * })) * Effect.runSync(Channel.runCollect(displayChannel)) // => [{ displayName: "User: Alice", isActive: true }, { displayName: "User: Bob", isActive: true }] * ``` * * @stability stable * @category sequencing * @since 2.0.0 */ (f: (o: OutElem, i: number) => OutElem2): (self: Channel) => Channel; /** * Maps the output of this channel using the specified function. * * **Example** (Mapping channel output) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class TransformError extends Data.TaggedError("TransformError")<{ * readonly reason: string * }> {} * * // Basic mapping of channel values * const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5]) * const doubledChannel = Channel.map(numbersChannel, (n) => n * 2) * Effect.runSync(Channel.runCollect(doubledChannel)) // => [2, 4, 6, 8, 10] * * // Transform string data * const wordsChannel = Channel.fromIterable(["hello", "world", "effect"]) * const upperCaseChannel = Channel.map(wordsChannel, (word) => word.toUpperCase()) * Effect.runSync(Channel.runCollect(upperCaseChannel)) // => ["HELLO", "WORLD", "EFFECT"] * * // Complex object transformation * type User = { id: number; name: string } * type UserDisplay = { displayName: string; isActive: boolean } * * const usersChannel = Channel.fromIterable([ * { id: 1, name: "Alice" }, * { id: 2, name: "Bob" } * ]) * const displayChannel = Channel.map(usersChannel, (user): UserDisplay => ({ * displayName: `User: ${user.name}`, * isActive: true * })) * Effect.runSync(Channel.runCollect(displayChannel)) // => [{ displayName: "User: Alice", isActive: true }, { displayName: "User: Bob", isActive: true }] * ``` * * @stability stable * @category sequencing * @since 2.0.0 */ (self: Channel, f: (o: OutElem, i: number) => OutElem2): Channel; }; /** * Maps the done value of this channel using the specified function. * * @stability stable * @category sequencing * @since 4.0.0 */ export declare const mapDone: { /** * Maps the done value of this channel using the specified function. * * @stability stable * @category sequencing * @since 4.0.0 */ (f: (o: OutDone) => OutDone2): (self: Channel) => Channel; /** * Maps the done value of this channel using the specified function. * * @stability stable * @category sequencing * @since 4.0.0 */ (self: Channel, f: (o: OutDone) => OutDone2): Channel; }; /** * Maps the done value of this channel using the specified effectful function. * * **When to use** * * Use when the terminal done value transformation needs services or can fail, * while emitted elements should pass through unchanged. * * @stability stable * @category sequencing * @since 4.0.0 */ export declare const mapDoneEffect: { /** * Maps the done value of this channel using the specified effectful function. * * **When to use** * * Use when the terminal done value transformation needs services or can fail, * while emitted elements should pass through unchanged. * * @stability stable * @category sequencing * @since 4.0.0 */ (f: (o: OutDone) => Effect.Effect): (self: Channel) => Channel; /** * Maps the done value of this channel using the specified effectful function. * * **When to use** * * Use when the terminal done value transformation needs services or can fail, * while emitted elements should pass through unchanged. * * @stability stable * @category sequencing * @since 4.0.0 */ (self: Channel, f: (o: OutDone) => Effect.Effect): Channel; }; /** * 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) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5]) * const processedChannel = Channel.mapEffect( * numbersChannel, * (n) => Effect.succeed(n * n) * ) * await Effect.runPromise(Channel.runCollect(processedChannel)) // => [1, 4, 9, 16, 25] * ``` * * @stability stable * @category sequencing * @since 2.0.0 */ export declare const mapEffect: { /** * 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) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5]) * const processedChannel = Channel.mapEffect( * numbersChannel, * (n) => Effect.succeed(n * n) * ) * await Effect.runPromise(Channel.runCollect(processedChannel)) // => [1, 4, 9, 16, 25] * ``` * * @stability stable * @category sequencing * @since 2.0.0 */ (f: (d: OutElem, i: number) => Effect.Effect, options?: { readonly concurrency?: Types.Concurrency | undefined; readonly unordered?: boolean | undefined; }): (self: Channel) => Channel; /** * 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) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5]) * const processedChannel = Channel.mapEffect( * numbersChannel, * (n) => Effect.succeed(n * n) * ) * await Effect.runPromise(Channel.runCollect(processedChannel)) // => [1, 4, 9, 16, 25] * ``` * * @stability stable * @category sequencing * @since 2.0.0 */ (self: Channel, f: (d: OutElem, i: number) => Effect.Effect, options?: { readonly concurrency?: Types.Concurrency | undefined; readonly unordered?: boolean | undefined; }): Channel; }; /** * Returns a new channel which is the same as this one but applies the given * function to the input channel’s input elements. * * @stability stable * @category sequencing * @since 2.0.0 */ export declare const mapInput: { /** * Returns a new channel which is the same as this one but applies the given * function to the input channel’s input elements. * * @stability stable * @category sequencing * @since 2.0.0 */ (f: (i: InElem2) => Effect.Effect): (self: Channel) => Channel; /** * Returns a new channel which is the same as this one but applies the given * function to the input channel’s input elements. * * @stability stable * @category sequencing * @since 2.0.0 */ (self: Channel, f: (i: InElem2) => Effect.Effect): Channel; }; /** * Returns a new channel which is the same as this one but applies the given * function to the input errors. * * @stability stable * @category sequencing * @since 2.0.0 */ export declare const mapInputError: { /** * Returns a new channel which is the same as this one but applies the given * function to the input errors. * * @stability stable * @category sequencing * @since 2.0.0 */ (f: (i: InErr2) => Effect.Effect): (self: Channel) => Channel; /** * Returns a new channel which is the same as this one but applies the given * function to the input errors. * * @stability stable * @category sequencing * @since 2.0.0 */ (self: Channel, f: (i: InErr2) => Effect.Effect): Channel; }; /** * 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** (Tapping channel output) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class LogError extends Data.TaggedError("LogError")<{ * readonly message: string * }> {} * * // Create a channel that outputs numbers * const numberChannel = Channel.fromIterable([1, 2, 3]) * * // Tap into each output element to perform side effects * const processed: Array = [] * const tappedChannel = Channel.tap( * numberChannel, * (n) => Effect.sync(() => processed.push(n)) * ) * * const observed = [await Effect.runPromise(Channel.runCollect(tappedChannel)), processed] // => [[1, 2, 3], [1, 2, 3]] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ export declare const tap: { /** * Applies a side effect function to each output element of the channel, * returning a new channel that emits the same elements. * * **Details** * * The `tap` function allows you to perform side effects (like logging or * debugging) on each element emitted by a channel without modifying the * elements themselves. * * **Example** (Tapping channel output) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class LogError extends Data.TaggedError("LogError")<{ * readonly message: string * }> {} * * // Create a channel that outputs numbers * const numberChannel = Channel.fromIterable([1, 2, 3]) * * // Tap into each output element to perform side effects * const processed: Array = [] * const tappedChannel = Channel.tap( * numberChannel, * (n) => Effect.sync(() => processed.push(n)) * ) * * const observed = [await Effect.runPromise(Channel.runCollect(tappedChannel)), processed] // => [[1, 2, 3], [1, 2, 3]] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ (f: (d: Types.NoInfer) => Effect.Effect, options?: { readonly concurrency?: Types.Concurrency | undefined; }): (self: Channel) => Channel; /** * 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** (Tapping channel output) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class LogError extends Data.TaggedError("LogError")<{ * readonly message: string * }> {} * * // Create a channel that outputs numbers * const numberChannel = Channel.fromIterable([1, 2, 3]) * * // Tap into each output element to perform side effects * const processed: Array = [] * const tappedChannel = Channel.tap( * numberChannel, * (n) => Effect.sync(() => processed.push(n)) * ) * * const observed = [await Effect.runPromise(Channel.runCollect(tappedChannel)), processed] // => [[1, 2, 3], [1, 2, 3]] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ (self: Channel, f: (d: Types.NoInfer) => Effect.Effect, options?: { readonly concurrency?: Types.Concurrency | undefined; }): Channel; }; /** * 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** (Flat mapping channel output) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class ProcessError extends Data.TaggedError("ProcessError")<{ * readonly cause: string * }> {} * * // Create a channel that outputs numbers * const numberChannel = Channel.fromIterable([1, 2, 3]) * * // FlatMap each number to create new channels * const flatMappedChannel = Channel.flatMap( * numberChannel, * (n) => * Channel.fromIterable(Array.from({ length: n }, (_, i) => `item-${n}-${i}`)) * ) * * Effect.runSync(Channel.runCollect(flatMappedChannel)) // => ["item-1-0", "item-2-0", "item-2-1", "item-3-0", "item-3-1", "item-3-2"] * ``` * * @stability stable * @category sequencing * @since 2.0.0 */ export declare const flatMap: { /** * 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** (Flat mapping channel output) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class ProcessError extends Data.TaggedError("ProcessError")<{ * readonly cause: string * }> {} * * // Create a channel that outputs numbers * const numberChannel = Channel.fromIterable([1, 2, 3]) * * // FlatMap each number to create new channels * const flatMappedChannel = Channel.flatMap( * numberChannel, * (n) => * Channel.fromIterable(Array.from({ length: n }, (_, i) => `item-${n}-${i}`)) * ) * * Effect.runSync(Channel.runCollect(flatMappedChannel)) // => ["item-1-0", "item-2-0", "item-2-1", "item-3-0", "item-3-1", "item-3-2"] * ``` * * @stability stable * @category sequencing * @since 2.0.0 */ (f: (d: OutElem) => Channel, options?: { readonly concurrency?: Types.Concurrency | undefined; readonly bufferSize?: number | undefined; }): (self: Channel) => Channel; /** * 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** (Flat mapping channel output) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class ProcessError extends Data.TaggedError("ProcessError")<{ * readonly cause: string * }> {} * * // Create a channel that outputs numbers * const numberChannel = Channel.fromIterable([1, 2, 3]) * * // FlatMap each number to create new channels * const flatMappedChannel = Channel.flatMap( * numberChannel, * (n) => * Channel.fromIterable(Array.from({ length: n }, (_, i) => `item-${n}-${i}`)) * ) * * Effect.runSync(Channel.runCollect(flatMappedChannel)) // => ["item-1-0", "item-2-0", "item-2-1", "item-3-0", "item-3-1", "item-3-2"] * ``` * * @stability stable * @category sequencing * @since 2.0.0 */ (self: Channel, f: (d: OutElem) => Channel, options?: { readonly concurrency?: Types.Concurrency | undefined; readonly bufferSize?: number | undefined; }): Channel; }; /** * Concatenates this channel with another channel created from the terminal value * of this channel. The new channel is created using the provided function. * * **Example** (Concatenating with completion values) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class ConcatError extends Data.TaggedError("ConcatError")<{ * readonly reason: string * }> {} * * // Create a channel that outputs numbers and terminates with sum * const numberChannel = Channel.fromIterable([1, 2, 3]).pipe( * Channel.concatWith((sum: void) => Channel.succeed(`Completed processing`)) * ) * * Effect.runSync(Channel.runCollect(numberChannel)) // => [1, 2, 3, "Completed processing"] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ export declare const concatWith: { /** * Concatenates this channel with another channel created from the terminal value * of this channel. The new channel is created using the provided function. * * **Example** (Concatenating with completion values) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class ConcatError extends Data.TaggedError("ConcatError")<{ * readonly reason: string * }> {} * * // Create a channel that outputs numbers and terminates with sum * const numberChannel = Channel.fromIterable([1, 2, 3]).pipe( * Channel.concatWith((sum: void) => Channel.succeed(`Completed processing`)) * ) * * Effect.runSync(Channel.runCollect(numberChannel)) // => [1, 2, 3, "Completed processing"] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ (f: (leftover: Types.NoInfer) => Channel): (self: Channel) => Channel; /** * Concatenates this channel with another channel created from the terminal value * of this channel. The new channel is created using the provided function. * * **Example** (Concatenating with completion values) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class ConcatError extends Data.TaggedError("ConcatError")<{ * readonly reason: string * }> {} * * // Create a channel that outputs numbers and terminates with sum * const numberChannel = Channel.fromIterable([1, 2, 3]).pipe( * Channel.concatWith((sum: void) => Channel.succeed(`Completed processing`)) * ) * * Effect.runSync(Channel.runCollect(numberChannel)) // => [1, 2, 3, "Completed processing"] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ (self: Channel, f: (leftover: Types.NoInfer) => Channel): Channel; }; /** * Concatenates this channel with another channel, so that the second channel * starts emitting values after the first channel has completed. * * **Example** (Concatenating channels) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class ConcatError extends Data.TaggedError("ConcatError")<{ * readonly reason: string * }> {} * * // Create two channels * const firstChannel = Channel.fromIterable([1, 2, 3]) * const secondChannel = Channel.fromIterable(["a", "b", "c"]) * * // Concatenate them * const concatenatedChannel = Channel.concat(firstChannel, secondChannel) * * Effect.runSync(Channel.runCollect(concatenatedChannel)) // => [1, 2, 3, "a", "b", "c"] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ export declare const concat: { /** * Concatenates this channel with another channel, so that the second channel * starts emitting values after the first channel has completed. * * **Example** (Concatenating channels) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class ConcatError extends Data.TaggedError("ConcatError")<{ * readonly reason: string * }> {} * * // Create two channels * const firstChannel = Channel.fromIterable([1, 2, 3]) * const secondChannel = Channel.fromIterable(["a", "b", "c"]) * * // Concatenate them * const concatenatedChannel = Channel.concat(firstChannel, secondChannel) * * Effect.runSync(Channel.runCollect(concatenatedChannel)) // => [1, 2, 3, "a", "b", "c"] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ (that: Channel): (self: Channel) => Channel; /** * Concatenates this channel with another channel, so that the second channel * starts emitting values after the first channel has completed. * * **Example** (Concatenating channels) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class ConcatError extends Data.TaggedError("ConcatError")<{ * readonly reason: string * }> {} * * // Create two channels * const firstChannel = Channel.fromIterable([1, 2, 3]) * const secondChannel = Channel.fromIterable(["a", "b", "c"]) * * // Concatenate them * const concatenatedChannel = Channel.concat(firstChannel, secondChannel) * * Effect.runSync(Channel.runCollect(concatenatedChannel)) // => [1, 2, 3, "a", "b", "c"] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ (self: Channel, that: Channel): Channel; }; /** * 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. * * @stability stable * @category sequencing * @since 4.0.0 */ export declare const combine: { /** * 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. * * @stability stable * @category sequencing * @since 4.0.0 */ (that: Channel, s: LazyArg, f: (s: S, pullLeft: Pull.Pull, pullRight: Pull.Pull) => Effect.Effect): (self: Channel) => Channel, Cause.Done.Extract, InElem & InElem2, InErr & InErr2, InDone & InDone2, Env | Env2 | R>; /** * Combines 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. * * @stability stable * @category sequencing * @since 4.0.0 */ (self: Channel, that: Channel, s: LazyArg, f: (s: S, pullLeft: Pull.Pull, pullRight: Pull.Pull) => Effect.Effect): Channel, Cause.Done.Extract, InElem & InElem2, InErr & InErr2, InDone & InDone2, Env | Env2 | R>; }; /** * 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. * * @stability stable * @category sequencing * @since 4.0.0 */ export declare const orElseIfEmpty: { /** * 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. * * @stability stable * @category sequencing * @since 4.0.0 */ (f: (leftover: Types.NoInfer) => Channel): (self: Channel) => Channel; /** * 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. * * @stability stable * @category sequencing * @since 4.0.0 */ (self: Channel, f: (leftover: Types.NoInfer) => Channel): Channel; }; /** * Flattens a channel of channels. * * **Example** (Flattening nested channels) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class FlattenError extends Data.TaggedError("FlattenError")<{ * readonly cause: string * }> {} * * // Create a channel that outputs channels * const nestedChannels = Channel.fromIterable([ * Channel.fromIterable([1, 2]), * Channel.fromIterable([3, 4]), * Channel.fromIterable([5, 6]) * ]) * * // Flatten the nested channels * const flattenedChannel = Channel.flatten(nestedChannels) * * Effect.runSync(Channel.runCollect(flattenedChannel)) // => [1, 2, 3, 4, 5, 6] * ``` * * @stability stable * @category constructors * @since 2.0.0 */ export declare const flatten: (channels: Channel, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1>) => Channel; /** * Flattens a channel that outputs arrays into a channel that outputs individual elements. * * **Example** (Flattening arrays of channel output) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class FlattenError extends Data.TaggedError("FlattenError")<{ * readonly message: string * }> {} * * // Create a channel that outputs arrays * const arrayChannel = Channel.fromIterable([ * [1, 2, 3], * [4, 5], * [6, 7, 8, 9] * ]) * * // Flatten the arrays into individual elements * const flattenedChannel = Channel.flattenArray(arrayChannel) * * Effect.runSync(Channel.runCollect(flattenedChannel)) // => [1, 2, 3, 4, 5, 6, 7, 8, 9] * ``` * * @stability stable * @category transforming * @since 4.0.0 */ export declare const flattenArray: (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>) => Channel; /** * Flattens a channel that emits `Take` values into a channel that emits the * `Take` outputs directly. * * **Details** * * Output `Take` values are emitted as non-empty arrays. Failed `Take` values * fail the returned channel. Done `Take` values complete the returned channel. * * @stability stable * @category transforming * @since 4.0.0 */ export declare const flattenTake: (self: Channel, OutErr2, OutDone2, InElem, InErr, InDone, Env>) => Channel, OutErr | OutErr2, OutDone, InElem, InErr, InDone, Env>; /** * Creates a new channel that consumes all output from the source channel * but emits nothing, preserving only the completion value. * * **Example** (Draining channel output) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // Create a channel that outputs values * const sourceChannel = Channel.fromIterable([1, 2, 3, 4, 5]) * * // Drain all output, keeping only the completion * const drainedChannel = Channel.drain(sourceChannel) * * Effect.runSync(Channel.runCollect(drainedChannel)) // => [] * ``` * * @stability stable * @category constructors * @since 2.0.0 */ export declare const drain: (self: Channel) => Channel; /** * Repeats this channel according to the provided schedule. * * @stability stable * @category repetition * @since 4.0.0 */ export declare const repeat: { /** * Repeats this channel according to the provided schedule. * * @stability stable * @category repetition * @since 4.0.0 */ (schedule: Schedule.Schedule, SE, SR> | (($: (_: Schedule.Schedule, SE, SR>) => Schedule.Schedule) => Schedule.Schedule, SE, SR>)): (self: Channel) => Channel; /** * Repeats this channel according to the provided schedule. * * @stability stable * @category repetition * @since 4.0.0 */ (self: Channel, schedule: Schedule.Schedule | (($: (_: Schedule.Schedule, SE, SR>) => Schedule.Schedule) => Schedule.Schedule, SE, SR>)): Channel; }; /** * Repeats this channel forever. * * @stability stable * @category repetition * @since 4.0.0 */ export declare const forever: (self: Channel) => Channel; /** * Runs a schedule step for each output element while preserving the emitted * elements. * * **Details** * * The schedule receives each output element as input. Schedule delays are * applied between emitted elements. If the schedule fails, the returned channel * fails. If the schedule finishes, the returned channel completes with the * schedule output. * * @stability stable * @category sequencing * @since 4.0.0 */ export declare const schedule: { /** * Runs a schedule step for each output element while preserving the emitted * elements. * * **Details** * * The schedule receives each output element as input. Schedule delays are * applied between emitted elements. If the schedule fails, the returned channel * fails. If the schedule finishes, the returned channel completes with the * schedule output. * * @stability stable * @category sequencing * @since 4.0.0 */ (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. * * @stability stable * @category sequencing * @since 4.0.0 */ (self: Channel, schedule: Schedule.Schedule): Channel; }; /** * Filters the output elements of a channel using a predicate function. * Elements that don't match the predicate are discarded. * * **Example** (Filtering channel output) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // Create a channel with mixed numbers * const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5, 6, 7, 8]) * * // Filter to keep only even numbers * const evenChannel = Channel.filter(numbersChannel, (n) => n % 2 === 0) * Effect.runSync(Channel.runCollect(evenChannel)) // => [2, 4, 6, 8] * * // Filter with type refinement * const mixedChannel = Channel.fromIterable([1, "hello", 2, "world", 3]) * const numbersOnlyChannel = Channel.filter( * mixedChannel, * (value): value is number => typeof value === "number" * ) * Effect.runSync(Channel.runCollect(numbersOnlyChannel)) // => [1, 2, 3] * ``` * * @stability stable * @category filtering * @since 4.0.0 */ export declare const filter: { /** * Filters the output elements of a channel using a predicate function. * Elements that don't match the predicate are discarded. * * **Example** (Filtering channel output) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // Create a channel with mixed numbers * const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5, 6, 7, 8]) * * // Filter to keep only even numbers * const evenChannel = Channel.filter(numbersChannel, (n) => n % 2 === 0) * Effect.runSync(Channel.runCollect(evenChannel)) // => [2, 4, 6, 8] * * // Filter with type refinement * const mixedChannel = Channel.fromIterable([1, "hello", 2, "world", 3]) * const numbersOnlyChannel = Channel.filter( * mixedChannel, * (value): value is number => typeof value === "number" * ) * Effect.runSync(Channel.runCollect(numbersOnlyChannel)) // => [1, 2, 3] * ``` * * @stability stable * @category filtering * @since 4.0.0 */ (refinement: Predicate.Refinement): (self: Channel) => Channel; /** * Filters the output elements of a channel using a predicate function. * Elements that don't match the predicate are discarded. * * **Example** (Filtering channel output) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // Create a channel with mixed numbers * const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5, 6, 7, 8]) * * // Filter to keep only even numbers * const evenChannel = Channel.filter(numbersChannel, (n) => n % 2 === 0) * Effect.runSync(Channel.runCollect(evenChannel)) // => [2, 4, 6, 8] * * // Filter with type refinement * const mixedChannel = Channel.fromIterable([1, "hello", 2, "world", 3]) * const numbersOnlyChannel = Channel.filter( * mixedChannel, * (value): value is number => typeof value === "number" * ) * Effect.runSync(Channel.runCollect(numbersOnlyChannel)) // => [1, 2, 3] * ``` * * @stability stable * @category filtering * @since 4.0.0 */ (predicate: Predicate.Predicate): (self: Channel) => Channel; /** * Filters the output elements of a channel using a predicate function. * Elements that don't match the predicate are discarded. * * **Example** (Filtering channel output) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // Create a channel with mixed numbers * const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5, 6, 7, 8]) * * // Filter to keep only even numbers * const evenChannel = Channel.filter(numbersChannel, (n) => n % 2 === 0) * Effect.runSync(Channel.runCollect(evenChannel)) // => [2, 4, 6, 8] * * // Filter with type refinement * const mixedChannel = Channel.fromIterable([1, "hello", 2, "world", 3]) * const numbersOnlyChannel = Channel.filter( * mixedChannel, * (value): value is number => typeof value === "number" * ) * Effect.runSync(Channel.runCollect(numbersOnlyChannel)) // => [1, 2, 3] * ``` * * @stability stable * @category filtering * @since 4.0.0 */ (self: Channel, refinement: Predicate.Refinement): Channel; /** * Filters the output elements of a channel using a predicate function. * Elements that don't match the predicate are discarded. * * **Example** (Filtering channel output) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // Create a channel with mixed numbers * const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5, 6, 7, 8]) * * // Filter to keep only even numbers * const evenChannel = Channel.filter(numbersChannel, (n) => n % 2 === 0) * Effect.runSync(Channel.runCollect(evenChannel)) // => [2, 4, 6, 8] * * // Filter with type refinement * const mixedChannel = Channel.fromIterable([1, "hello", 2, "world", 3]) * const numbersOnlyChannel = Channel.filter( * mixedChannel, * (value): value is number => typeof value === "number" * ) * Effect.runSync(Channel.runCollect(numbersOnlyChannel)) // => [1, 2, 3] * ``` * * @stability stable * @category filtering * @since 4.0.0 */ (self: Channel, predicate: Predicate.Predicate): Channel; }; /** * Filters and maps output elements using a `Filter`. * * **When to use** * * Use to keep only channel output elements accepted by a `Filter` and emit * each filter success value. * * **Details** * * Successful filter results are emitted as mapped values. Failed filter * results are discarded. The source channel's errors and done value are * preserved. * * @see {@link filter} for keeping original output elements with a predicate * @see {@link filterMapEffect} for using an effectful `Filter` * @see {@link filterMapArray} for filtering arrays of output elements * * @stability stable * @category filtering * @since 4.0.0 */ export declare const filterMap: { /** * Filters and maps output elements using a `Filter`. * * **When to use** * * Use to keep only channel output elements accepted by a `Filter` and emit * each filter success value. * * **Details** * * Successful filter results are emitted as mapped values. Failed filter * results are discarded. The source channel's errors and done value are * preserved. * * @see {@link filter} for keeping original output elements with a predicate * @see {@link filterMapEffect} for using an effectful `Filter` * @see {@link filterMapArray} for filtering arrays of output elements * * @stability stable * @category filtering * @since 4.0.0 */ (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 * * @stability stable * @category filtering * @since 4.0.0 */ (self: Channel, filter: Filter.Filter): Channel; }; /** * Filters output elements with an effectful predicate. * * **When to use** * * Use when the keep/discard decision depends on an Effect or service and * predicate failures should fail the returned channel. * * **Details** * * Elements for which the predicate succeeds with `true` are emitted. Elements * for which the predicate succeeds with `false` are discarded. Predicate * failures fail the returned channel. * * @stability stable * @category filtering * @since 4.0.0 */ export declare const filterEffect: { /** * Filters output elements with an effectful predicate. * * **When to use** * * Use when the keep/discard decision depends on an Effect or service and * predicate failures should fail the returned channel. * * **Details** * * Elements for which the predicate succeeds with `true` are emitted. Elements * for which the predicate succeeds with `false` are discarded. Predicate * failures fail the returned channel. * * @stability stable * @category filtering * @since 4.0.0 */ (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. * * @stability stable * @category filtering * @since 4.0.0 */ (self: Channel, predicate: (a: OutElem) => Effect.Effect): Channel; }; /** * Filters and maps output elements using an effectful `Filter`. * * **When to use** * * Use to apply effectful logic that can discard channel output elements and * emit transformed values for the elements that pass. * * **Details** * * Successful filter results are emitted as mapped values. Failed filter * results are discarded. Failures from the effectful filter fail the returned * channel. * * @see {@link filterMap} for using a synchronous `Filter` * @see {@link filterEffect} for effectfully keeping original output elements * @see {@link mapEffect} for effectfully transforming every output element * @see {@link filterMapArrayEffect} for effectful filtering of array outputs * * @stability stable * @category filtering * @since 4.0.0 */ export declare const filterMapEffect: { /** * Filters and maps output elements using an effectful `Filter`. * * **When to use** * * Use to apply effectful logic that can discard channel output elements and * emit transformed values for the elements that pass. * * **Details** * * Successful filter results are emitted as mapped values. Failed filter * results are discarded. Failures from the effectful filter fail the returned * channel. * * @see {@link filterMap} for using a synchronous `Filter` * @see {@link filterEffect} for effectfully keeping original output elements * @see {@link mapEffect} for effectfully transforming every output element * @see {@link filterMapArrayEffect} for effectful filtering of array outputs * * @stability stable * @category filtering * @since 4.0.0 */ (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 * * @stability stable * @category filtering * @since 4.0.0 */ (self: Channel, filter: Filter.FilterEffect): Channel; }; /** * 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** (Filtering array output) * * ```ts import.meta.vitest * import { Array, Channel, Effect } from "effect" * * const nonEmptyArrayPredicate = Array.isReadonlyArrayNonEmpty * * // Create a channel that outputs arrays of mixed data * const arrayChannel = Channel.fromIterable([ * Array.make(1, 2, 3, 4, 5), * Array.make(6, 7, 8, 9, 10), * Array.make(11, 12, 13, 14, 15) * ]).pipe(Channel.filter(nonEmptyArrayPredicate)) * * // Filter arrays to keep only even numbers * const evenArraysChannel = Channel.filterArray(arrayChannel, (n) => n % 2 === 0) * Effect.runSync(Channel.runCollect(evenArraysChannel)) // => [[2, 4], [6, 8, 10], [12, 14]] * // Note: Only non-empty filtered arrays are emitted * * // Arrays that would become empty after filtering are discarded entirely * const oddChannel = Channel.fromIterable([ * Array.make(1, 3, 5), * Array.make(2, 4), * Array.make(7, 9) * ]).pipe(Channel.filter(nonEmptyArrayPredicate)) * const filteredOddChannel = Channel.filterArray(oddChannel, (n) => n % 2 === 0) * Effect.runSync(Channel.runCollect(filteredOddChannel)) // => [[2, 4]] * ``` * * @stability stable * @category filtering * @since 4.0.0 */ export declare const filterArray: { /** * Filters arrays of elements emitted by a channel, applying the filter * to each element within the arrays and only emitting non-empty filtered arrays. * * **Example** (Filtering array output) * * ```ts import.meta.vitest * import { Array, Channel, Effect } from "effect" * * const nonEmptyArrayPredicate = Array.isReadonlyArrayNonEmpty * * // Create a channel that outputs arrays of mixed data * const arrayChannel = Channel.fromIterable([ * Array.make(1, 2, 3, 4, 5), * Array.make(6, 7, 8, 9, 10), * Array.make(11, 12, 13, 14, 15) * ]).pipe(Channel.filter(nonEmptyArrayPredicate)) * * // Filter arrays to keep only even numbers * const evenArraysChannel = Channel.filterArray(arrayChannel, (n) => n % 2 === 0) * Effect.runSync(Channel.runCollect(evenArraysChannel)) // => [[2, 4], [6, 8, 10], [12, 14]] * // Note: Only non-empty filtered arrays are emitted * * // Arrays that would become empty after filtering are discarded entirely * const oddChannel = Channel.fromIterable([ * Array.make(1, 3, 5), * Array.make(2, 4), * Array.make(7, 9) * ]).pipe(Channel.filter(nonEmptyArrayPredicate)) * const filteredOddChannel = Channel.filterArray(oddChannel, (n) => n % 2 === 0) * Effect.runSync(Channel.runCollect(filteredOddChannel)) // => [[2, 4]] * ``` * * @stability stable * @category filtering * @since 4.0.0 */ (refinement: Predicate.Refinement): (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>) => Channel, OutErr, OutDone, InElem, InErr, InDone, Env>; /** * Filters arrays of elements emitted by a channel, applying the filter * to each element within the arrays and only emitting non-empty filtered arrays. * * **Example** (Filtering array output) * * ```ts import.meta.vitest * import { Array, Channel, Effect } from "effect" * * const nonEmptyArrayPredicate = Array.isReadonlyArrayNonEmpty * * // Create a channel that outputs arrays of mixed data * const arrayChannel = Channel.fromIterable([ * Array.make(1, 2, 3, 4, 5), * Array.make(6, 7, 8, 9, 10), * Array.make(11, 12, 13, 14, 15) * ]).pipe(Channel.filter(nonEmptyArrayPredicate)) * * // Filter arrays to keep only even numbers * const evenArraysChannel = Channel.filterArray(arrayChannel, (n) => n % 2 === 0) * Effect.runSync(Channel.runCollect(evenArraysChannel)) // => [[2, 4], [6, 8, 10], [12, 14]] * // Note: Only non-empty filtered arrays are emitted * * // Arrays that would become empty after filtering are discarded entirely * const oddChannel = Channel.fromIterable([ * Array.make(1, 3, 5), * Array.make(2, 4), * Array.make(7, 9) * ]).pipe(Channel.filter(nonEmptyArrayPredicate)) * const filteredOddChannel = Channel.filterArray(oddChannel, (n) => n % 2 === 0) * Effect.runSync(Channel.runCollect(filteredOddChannel)) // => [[2, 4]] * ``` * * @stability stable * @category filtering * @since 4.0.0 */ (predicate: Predicate.Predicate>): (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>) => Channel, OutErr, OutDone, InElem, InErr, InDone, Env>; /** * Filters arrays of elements emitted by a channel, applying the filter * to each element within the arrays and only emitting non-empty filtered arrays. * * **Example** (Filtering array output) * * ```ts import.meta.vitest * import { Array, Channel, Effect } from "effect" * * const nonEmptyArrayPredicate = Array.isReadonlyArrayNonEmpty * * // Create a channel that outputs arrays of mixed data * const arrayChannel = Channel.fromIterable([ * Array.make(1, 2, 3, 4, 5), * Array.make(6, 7, 8, 9, 10), * Array.make(11, 12, 13, 14, 15) * ]).pipe(Channel.filter(nonEmptyArrayPredicate)) * * // Filter arrays to keep only even numbers * const evenArraysChannel = Channel.filterArray(arrayChannel, (n) => n % 2 === 0) * Effect.runSync(Channel.runCollect(evenArraysChannel)) // => [[2, 4], [6, 8, 10], [12, 14]] * // Note: Only non-empty filtered arrays are emitted * * // Arrays that would become empty after filtering are discarded entirely * const oddChannel = Channel.fromIterable([ * Array.make(1, 3, 5), * Array.make(2, 4), * Array.make(7, 9) * ]).pipe(Channel.filter(nonEmptyArrayPredicate)) * const filteredOddChannel = Channel.filterArray(oddChannel, (n) => n % 2 === 0) * Effect.runSync(Channel.runCollect(filteredOddChannel)) // => [[2, 4]] * ``` * * @stability stable * @category filtering * @since 4.0.0 */ (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>, refinement: Predicate.Refinement): Channel, OutErr, OutDone, InElem, InErr, InDone, Env>; /** * Filters arrays of elements emitted by a channel, applying the filter * to each element within the arrays and only emitting non-empty filtered arrays. * * **Example** (Filtering array output) * * ```ts import.meta.vitest * import { Array, Channel, Effect } from "effect" * * const nonEmptyArrayPredicate = Array.isReadonlyArrayNonEmpty * * // Create a channel that outputs arrays of mixed data * const arrayChannel = Channel.fromIterable([ * Array.make(1, 2, 3, 4, 5), * Array.make(6, 7, 8, 9, 10), * Array.make(11, 12, 13, 14, 15) * ]).pipe(Channel.filter(nonEmptyArrayPredicate)) * * // Filter arrays to keep only even numbers * const evenArraysChannel = Channel.filterArray(arrayChannel, (n) => n % 2 === 0) * Effect.runSync(Channel.runCollect(evenArraysChannel)) // => [[2, 4], [6, 8, 10], [12, 14]] * // Note: Only non-empty filtered arrays are emitted * * // Arrays that would become empty after filtering are discarded entirely * const oddChannel = Channel.fromIterable([ * Array.make(1, 3, 5), * Array.make(2, 4), * Array.make(7, 9) * ]).pipe(Channel.filter(nonEmptyArrayPredicate)) * const filteredOddChannel = Channel.filterArray(oddChannel, (n) => n % 2 === 0) * Effect.runSync(Channel.runCollect(filteredOddChannel)) // => [[2, 4]] * ``` * * @stability stable * @category filtering * @since 4.0.0 */ (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>, predicate: Predicate.Predicate>): Channel, OutErr, OutDone, InElem, InErr, InDone, Env>; }; /** * Filters and maps each element inside emitted non-empty arrays using a * `Filter`. * * **Details** * * Successful filter results are kept as mapped values. Failed filter results * are removed from the array. Arrays that become empty are discarded. * * @stability stable * @category filtering * @since 4.0.0 */ export declare const filterMapArray: { /** * Filters and maps each element inside emitted non-empty arrays using a * `Filter`. * * **Details** * * Successful filter results are kept as mapped values. Failed filter results * are removed from the array. Arrays that become empty are discarded. * * @stability stable * @category filtering * @since 4.0.0 */ (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. * * @stability stable * @category filtering * @since 4.0.0 */ (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>, filter: Filter.Filter): Channel, OutErr, OutDone, InElem, InErr, InDone, Env>; }; /** * Filters each element inside emitted non-empty arrays with an effectful * predicate. * * **When to use** * * Use when filtering array-valued channel outputs requires Effects or services, * and arrays that become empty should be skipped. * * **Details** * * The predicate receives the element and its index within the array. Elements * for which the predicate succeeds with `true` are kept. Arrays that become * empty are discarded. Predicate failures fail the returned channel. * * @stability stable * @category filtering * @since 4.0.0 */ export declare const filterArrayEffect: { /** * Filters each element inside emitted non-empty arrays with an effectful * predicate. * * **When to use** * * Use when filtering array-valued channel outputs requires Effects or services, * and arrays that become empty should be skipped. * * **Details** * * The predicate receives the element and its index within the array. Elements * for which the predicate succeeds with `true` are kept. Arrays that become * empty are discarded. Predicate failures fail the returned channel. * * @stability stable * @category filtering * @since 4.0.0 */ (predicate: (a: Types.NoInfer, index: number) => Effect.Effect): (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>) => Channel, OutErr | E, OutDone, InElem, InErr, InDone, Env | R>; /** * Filters each element inside emitted non-empty arrays with an effectful * predicate. * * **When to use** * * Use when filtering array-valued channel outputs requires Effects or services, * and arrays that become empty should be skipped. * * **Details** * * The predicate receives the element and its index within the array. Elements * for which the predicate succeeds with `true` are kept. Arrays that become * empty are discarded. Predicate failures fail the returned channel. * * @stability stable * @category filtering * @since 4.0.0 */ (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>, predicate: (a: Types.NoInfer, index: number) => Effect.Effect): Channel, OutErr | E, OutDone, InElem, InErr, InDone, Env | R>; }; /** * Filters and maps each element inside emitted non-empty arrays using an * effectful `Filter`. * * **When to use** * * Use when array-valued channel outputs need an effectful filter-map that can * fail and can discard arrays that become empty. * * **Details** * * Successful filter results are kept as mapped values. Failed filter results * are removed from the array. Arrays that become empty are discarded. Failures * from the effectful filter fail the returned channel. * * @stability stable * @category filtering * @since 4.0.0 */ export declare const filterMapArrayEffect: { /** * Filters and maps each element inside emitted non-empty arrays using an * effectful `Filter`. * * **When to use** * * Use when array-valued channel outputs need an effectful filter-map that can * fail and can discard arrays that become empty. * * **Details** * * Successful filter results are kept as mapped values. Failed filter results * are removed from the array. Arrays that become empty are discarded. Failures * from the effectful filter fail the returned channel. * * @stability stable * @category filtering * @since 4.0.0 */ (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. * * @stability stable * @category filtering * @since 4.0.0 */ (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>, filter: Filter.FilterEffect): Channel, OutErr | EX, OutDone, InElem, InErr, InDone, Env | RX>; }; /** * Maps over a channel statefully with an accumulator, where each element can produce multiple output values. * * **Example** (Mapping with accumulated state) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // Create a channel with numbers * const numbersChannel = Channel.fromIterable([1, 2, 3, 4]) * * // Use mapAccum to create running sums and emit both current and sum * const runningSum = Channel.mapAccum( * numbersChannel, * () => 0, // initial accumulator state * (sum, current) => { * const newSum = sum + current * // Return [newState, outputValues] * return [newSum, [current, newSum]] as const * } * ) * // Using with Effect for async processing * const asyncMapAccum = Channel.mapAccum( * numbersChannel, * () => "", * (acc, value) => * Effect.gen(function*() { * const newAcc = acc + value.toString() * return [newAcc, [`${value}-processed`, newAcc]] as const * }) * ) * Effect.runSync(Channel.runCollect(runningSum)) // => [1, 1, 2, 3, 3, 6, 4, 10] * Effect.runSync(Channel.runCollect(asyncMapAccum)) // => ["1-processed", "1", "2-processed", "12", "3-processed", "123", "4-processed", "1234"] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ export declare const mapAccum: { /** * Maps over a channel statefully with an accumulator, where each element can produce multiple output values. * * **Example** (Mapping with accumulated state) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // Create a channel with numbers * const numbersChannel = Channel.fromIterable([1, 2, 3, 4]) * * // Use mapAccum to create running sums and emit both current and sum * const runningSum = Channel.mapAccum( * numbersChannel, * () => 0, // initial accumulator state * (sum, current) => { * const newSum = sum + current * // Return [newState, outputValues] * return [newSum, [current, newSum]] as const * } * ) * // Using with Effect for async processing * const asyncMapAccum = Channel.mapAccum( * numbersChannel, * () => "", * (acc, value) => * Effect.gen(function*() { * const newAcc = acc + value.toString() * return [newAcc, [`${value}-processed`, newAcc]] as const * }) * ) * Effect.runSync(Channel.runCollect(runningSum)) // => [1, 1, 2, 3, 3, 6, 4, 10] * Effect.runSync(Channel.runCollect(asyncMapAccum)) // => ["1-processed", "1", "2-processed", "12", "3-processed", "123", "4-processed", "1234"] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ (initial: LazyArg, f: (s: S, a: Types.NoInfer) => Effect.Effect], E, R> | readonly [state: S, values: ReadonlyArray], options?: { readonly onHalt?: ((state: S) => Array) | undefined; }): (self: Channel) => Channel; /** * Maps over a channel statefully with an accumulator, where each element can produce multiple output values. * * **Example** (Mapping with accumulated state) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // Create a channel with numbers * const numbersChannel = Channel.fromIterable([1, 2, 3, 4]) * * // Use mapAccum to create running sums and emit both current and sum * const runningSum = Channel.mapAccum( * numbersChannel, * () => 0, // initial accumulator state * (sum, current) => { * const newSum = sum + current * // Return [newState, outputValues] * return [newSum, [current, newSum]] as const * } * ) * // Using with Effect for async processing * const asyncMapAccum = Channel.mapAccum( * numbersChannel, * () => "", * (acc, value) => * Effect.gen(function*() { * const newAcc = acc + value.toString() * return [newAcc, [`${value}-processed`, newAcc]] as const * }) * ) * Effect.runSync(Channel.runCollect(runningSum)) // => [1, 1, 2, 3, 3, 6, 4, 10] * Effect.runSync(Channel.runCollect(asyncMapAccum)) // => ["1-processed", "1", "2-processed", "12", "3-processed", "123", "4-processed", "1234"] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ (self: Channel, initial: LazyArg, f: (s: S, a: Types.NoInfer) => Effect.Effect], E, R> | readonly [state: S, values: ReadonlyArray], options?: { readonly onHalt?: ((state: S) => Array) | undefined; }): Channel; }; /** * Transforms a channel statefully by scanning over its output with an accumulator function. * Emits the intermediate results of the scan operation. * * **Example** (Scanning channel output) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // Create a channel with numbers * const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5]) * * // Scan to create running sum * const runningSumChannel = Channel.scan(numbersChannel, 0, (sum, n) => sum + n) * Effect.runSync(Channel.runCollect(runningSumChannel)) // => [0, 1, 3, 6, 10, 15] * // Note: emits the initial value and each intermediate result * * // Scan with string concatenation * const wordsChannel = Channel.fromIterable(["hello", "world", "from", "effect"]) * const sentenceChannel = Channel.scan( * wordsChannel, * "", * (sentence, word) => sentence === "" ? word : `${sentence} ${word}` * ) * Effect.runSync(Channel.runCollect(sentenceChannel)) // => ["", "hello", "hello world", "hello world from", "hello world from effect"] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ export declare const scan: { /** * Transforms a channel statefully by scanning over its output with an accumulator function. * Emits the intermediate results of the scan operation. * * **Example** (Scanning channel output) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // Create a channel with numbers * const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5]) * * // Scan to create running sum * const runningSumChannel = Channel.scan(numbersChannel, 0, (sum, n) => sum + n) * Effect.runSync(Channel.runCollect(runningSumChannel)) // => [0, 1, 3, 6, 10, 15] * // Note: emits the initial value and each intermediate result * * // Scan with string concatenation * const wordsChannel = Channel.fromIterable(["hello", "world", "from", "effect"]) * const sentenceChannel = Channel.scan( * wordsChannel, * "", * (sentence, word) => sentence === "" ? word : `${sentence} ${word}` * ) * Effect.runSync(Channel.runCollect(sentenceChannel)) // => ["", "hello", "hello world", "hello world from", "hello world from effect"] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ (initial: S, f: (s: S, a: Types.NoInfer) => S): (self: Channel) => Channel; /** * Transforms a channel statefully by scanning over its output with an accumulator function. * Emits the intermediate results of the scan operation. * * **Example** (Scanning channel output) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // Create a channel with numbers * const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5]) * * // Scan to create running sum * const runningSumChannel = Channel.scan(numbersChannel, 0, (sum, n) => sum + n) * Effect.runSync(Channel.runCollect(runningSumChannel)) // => [0, 1, 3, 6, 10, 15] * // Note: emits the initial value and each intermediate result * * // Scan with string concatenation * const wordsChannel = Channel.fromIterable(["hello", "world", "from", "effect"]) * const sentenceChannel = Channel.scan( * wordsChannel, * "", * (sentence, word) => sentence === "" ? word : `${sentence} ${word}` * ) * Effect.runSync(Channel.runCollect(sentenceChannel)) // => ["", "hello", "hello world", "hello world from", "hello world from effect"] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ (self: Channel, initial: S, f: (s: S, a: Types.NoInfer) => S): Channel; }; /** * Transforms a channel statefully by scanning over its output with an effectful accumulator function. * Emits the intermediate results of the scan operation. * * **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.meta.vitest * import { Channel, Data, Effect } from "effect" * * class ScanError extends Data.TaggedError("ScanError")<{ * readonly reason: string * }> {} * * // Create a channel with numbers * const numbersChannel = Channel.fromIterable([1, 2, 3, 4]) * * // Effectful scan with async operations * const asyncScanChannel = Channel.scanEffect( * numbersChannel, * "", * (acc, value) => * Effect.gen(function*() { * return acc + value.toString() * }) * ) * await Effect.runPromise(Channel.runCollect(asyncScanChannel)) // => ["", "1", "12", "123", "1234"] * * // Scan with error handling * const errorHandlingScan = Channel.scanEffect( * numbersChannel, * 0, * (sum, n) => { * if (n < 0) { * return Effect.fail(new ScanError({ reason: "negative number" })) * } * return Effect.succeed(sum + n) * } * ) * await Effect.runPromise(Channel.runCollect(errorHandlingScan)) // => [0, 1, 3, 6, 10] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ export declare const scanEffect: { /** * Transforms a channel statefully by scanning over its output with an effectful accumulator function. * Emits the intermediate results of the scan operation. * * **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.meta.vitest * import { Channel, Data, Effect } from "effect" * * class ScanError extends Data.TaggedError("ScanError")<{ * readonly reason: string * }> {} * * // Create a channel with numbers * const numbersChannel = Channel.fromIterable([1, 2, 3, 4]) * * // Effectful scan with async operations * const asyncScanChannel = Channel.scanEffect( * numbersChannel, * "", * (acc, value) => * Effect.gen(function*() { * return acc + value.toString() * }) * ) * await Effect.runPromise(Channel.runCollect(asyncScanChannel)) // => ["", "1", "12", "123", "1234"] * * // Scan with error handling * const errorHandlingScan = Channel.scanEffect( * numbersChannel, * 0, * (sum, n) => { * if (n < 0) { * return Effect.fail(new ScanError({ reason: "negative number" })) * } * return Effect.succeed(sum + n) * } * ) * await Effect.runPromise(Channel.runCollect(errorHandlingScan)) // => [0, 1, 3, 6, 10] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ (initial: S, f: (s: S, a: Types.NoInfer) => Effect.Effect): (self: Channel) => Channel; /** * Transforms a channel statefully by scanning over its output with an effectful accumulator function. * Emits the intermediate results of the scan operation. * * **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.meta.vitest * import { Channel, Data, Effect } from "effect" * * class ScanError extends Data.TaggedError("ScanError")<{ * readonly reason: string * }> {} * * // Create a channel with numbers * const numbersChannel = Channel.fromIterable([1, 2, 3, 4]) * * // Effectful scan with async operations * const asyncScanChannel = Channel.scanEffect( * numbersChannel, * "", * (acc, value) => * Effect.gen(function*() { * return acc + value.toString() * }) * ) * await Effect.runPromise(Channel.runCollect(asyncScanChannel)) // => ["", "1", "12", "123", "1234"] * * // Scan with error handling * const errorHandlingScan = Channel.scanEffect( * numbersChannel, * 0, * (sum, n) => { * if (n < 0) { * return Effect.fail(new ScanError({ reason: "negative number" })) * } * return Effect.succeed(sum + n) * } * ) * await Effect.runPromise(Channel.runCollect(errorHandlingScan)) // => [0, 1, 3, 6, 10] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ (self: Channel, initial: S, f: (s: S, a: Types.NoInfer) => Effect.Effect): Channel; }; /** * Catches any cause of failure from the channel and allows recovery by * creating a new channel based on the caught cause. * * **Example** (Recovering from failure causes) * * ```ts import.meta.vitest * import { Cause, Channel, Data, Effect } from "effect" * * class ProcessError extends Data.TaggedError("ProcessError")<{ * readonly reason: string * }> {} * * class RecoveryError extends Data.TaggedError("RecoveryError")<{ * readonly message: string * }> {} * * // Create a failing channel * const failingChannel = Channel.fail( * new ProcessError({ reason: "network error" }) * ) * * // Catch the cause and provide recovery * const recoveredChannel = Channel.catchCause(failingChannel, (cause) => { * if (Cause.hasFails(cause)) { * return Channel.succeed("Recovered from failure") * } * return Channel.succeed("Recovered from interruption") * }) * * Effect.runSync(Channel.runCollect(recoveredChannel)) // => ["Recovered from failure"] * ``` * * @stability stable * @category error handling * @since 2.0.0 */ export declare const catchCause: { /** * Catches any cause of failure from the channel and allows recovery by * creating a new channel based on the caught cause. * * **Example** (Recovering from failure causes) * * ```ts import.meta.vitest * import { Cause, Channel, Data, Effect } from "effect" * * class ProcessError extends Data.TaggedError("ProcessError")<{ * readonly reason: string * }> {} * * class RecoveryError extends Data.TaggedError("RecoveryError")<{ * readonly message: string * }> {} * * // Create a failing channel * const failingChannel = Channel.fail( * new ProcessError({ reason: "network error" }) * ) * * // Catch the cause and provide recovery * const recoveredChannel = Channel.catchCause(failingChannel, (cause) => { * if (Cause.hasFails(cause)) { * return Channel.succeed("Recovered from failure") * } * return Channel.succeed("Recovered from interruption") * }) * * Effect.runSync(Channel.runCollect(recoveredChannel)) // => ["Recovered from failure"] * ``` * * @stability stable * @category error handling * @since 2.0.0 */ (f: (d: Cause.Cause) => Channel): (self: Channel) => Channel; /** * Catches any cause of failure from the channel and allows recovery by * creating a new channel based on the caught cause. * * **Example** (Recovering from failure causes) * * ```ts import.meta.vitest * import { Cause, Channel, Data, Effect } from "effect" * * class ProcessError extends Data.TaggedError("ProcessError")<{ * readonly reason: string * }> {} * * class RecoveryError extends Data.TaggedError("RecoveryError")<{ * readonly message: string * }> {} * * // Create a failing channel * const failingChannel = Channel.fail( * new ProcessError({ reason: "network error" }) * ) * * // Catch the cause and provide recovery * const recoveredChannel = Channel.catchCause(failingChannel, (cause) => { * if (Cause.hasFails(cause)) { * return Channel.succeed("Recovered from failure") * } * return Channel.succeed("Recovered from interruption") * }) * * Effect.runSync(Channel.runCollect(recoveredChannel)) // => ["Recovered from failure"] * ``` * * @stability stable * @category error handling * @since 2.0.0 */ (self: Channel, f: (d: Cause.Cause) => Channel): Channel; }; /** * Recovers from defects using the provided function. * * **Details** * * Typed failures and interruptions are not caught. * * **Gotchas** * * `catchDefect` recovers any cause that contains a defect, including causes * that also contain typed errors. Typed error handlers such as `catch` skip * those causes, so defects always take precedence. * * **Example** (Recovering from a defect) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const channel = Channel.fromEffect(Effect.die("boom")).pipe( * Channel.catchDefect((defect) => Channel.succeed(`recovered: ${defect}`)) * ) * * Effect.runSync(Channel.runCollect(channel)) // => ["recovered: boom"] * ``` * * @stability stable * @category error handling * @since 4.0.0 */ export declare const catchDefect: { /** * Recovers from defects using the provided function. * * **Details** * * Typed failures and interruptions are not caught. * * **Gotchas** * * `catchDefect` recovers any cause that contains a defect, including causes * that also contain typed errors. Typed error handlers such as `catch` skip * those causes, so defects always take precedence. * * **Example** (Recovering from a defect) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const channel = Channel.fromEffect(Effect.die("boom")).pipe( * Channel.catchDefect((defect) => Channel.succeed(`recovered: ${defect}`)) * ) * * Effect.runSync(Channel.runCollect(channel)) // => ["recovered: boom"] * ``` * * @stability stable * @category error handling * @since 4.0.0 */ (f: (defect: unknown) => Channel): (self: Channel) => Channel; /** * Recovers from defects using the provided function. * * **Details** * * Typed failures and interruptions are not caught. * * **Gotchas** * * `catchDefect` recovers any cause that contains a defect, including causes * that also contain typed errors. Typed error handlers such as `catch` skip * those causes, so defects always take precedence. * * **Example** (Recovering from a defect) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const channel = Channel.fromEffect(Effect.die("boom")).pipe( * Channel.catchDefect((defect) => Channel.succeed(`recovered: ${defect}`)) * ) * * Effect.runSync(Channel.runCollect(channel)) // => ["recovered: boom"] * ``` * * @stability stable * @category error handling * @since 4.0.0 */ (self: Channel, f: (defect: unknown) => Channel): Channel; }; /** * Runs an effect with the full failure `Cause` when the channel fails, then * fails the returned channel with the original cause. * * **When to use** * * Use when observing the full channel failure `Cause` is needed without * changing successful output or replacing the original cause. * * **Details** * * Use this for observing failures, such as logging or metrics. If the observer * effect fails, that failure can fail the returned channel. * * @stability stable * @category error handling * @since 4.0.0 */ export declare const tapCause: { /** * Runs an effect with the full failure `Cause` when the channel fails, then * fails the returned channel with the original cause. * * **When to use** * * Use when observing the full channel failure `Cause` is needed without * changing successful output or replacing the original cause. * * **Details** * * Use this for observing failures, such as logging or metrics. If the observer * effect fails, that failure can fail the returned channel. * * @stability stable * @category error handling * @since 4.0.0 */ (f: (d: Cause.Cause) => Effect.Effect): (self: Channel) => Channel; /** * Runs an effect with the full failure `Cause` when the channel fails, then * fails the returned channel with the original cause. * * **When to use** * * Use when observing the full channel failure `Cause` is needed without * changing successful output or replacing the original cause. * * **Details** * * Use this for observing failures, such as logging or metrics. If the observer * effect fails, that failure can fail the returned channel. * * @stability stable * @category error handling * @since 4.0.0 */ (self: Channel, f: (d: Cause.Cause) => Effect.Effect): Channel; }; /** * Catches causes of failure that match a specific filter, allowing * conditional error recovery based on the type of failure. * * **When to use** * * Use to recover a channel only when its full `Cause` satisfies a boolean * predicate. * * **Details** * * When the predicate matches, the recovery function receives the original * cause. When it does not match, the returned channel fails with the original * cause. * * @see {@link catchCauseFilter} for selecting causes with a `Filter` * @see {@link catchCause} for recovering from every cause * @see {@link catchIf} for recovering from typed channel errors * * @stability stable * @category error handling * @since 4.0.0 */ export declare const catchCauseIf: { /** * Catches causes of failure that match a specific filter, allowing * conditional error recovery based on the type of failure. * * **When to use** * * Use to recover a channel only when its full `Cause` satisfies a boolean * predicate. * * **Details** * * When the predicate matches, the recovery function receives the original * cause. When it does not match, the returned channel fails with the original * cause. * * @see {@link catchCauseFilter} for selecting causes with a `Filter` * @see {@link catchCause} for recovering from every cause * @see {@link catchIf} for recovering from typed channel errors * * @stability stable * @category error handling * @since 4.0.0 */ (predicate: Predicate.Predicate>, f: (cause: Cause.Cause) => Channel): (self: Channel) => Channel; /** * Catches causes of failure that match a specific filter, allowing * conditional error recovery based on the type of failure. * * **When to use** * * Use to recover a channel only when its full `Cause` satisfies a boolean * predicate. * * **Details** * * When the predicate matches, the recovery function receives the original * cause. When it does not match, the returned channel fails with the original * cause. * * @see {@link catchCauseFilter} for selecting causes with a `Filter` * @see {@link catchCause} for recovering from every cause * @see {@link catchIf} for recovering from typed channel errors * * @stability stable * @category error handling * @since 4.0.0 */ (self: Channel, predicate: Predicate.Predicate>, f: (cause: Cause.Cause) => Channel): Channel; }; /** * Recovers from channel failures whose full `Cause` is selected by a `Filter`. * * **When to use** * * Use when you need to recover a channel only from causes selected by a * `Filter`, while giving the recovery both the selected value and the original * `Cause`. * * **Details** * * When the filter succeeds, the recovery function receives the selected value * and the original cause. When the filter fails, the returned channel fails * with the residual cause produced by the filter. * * @see {@link catchCauseIf} for selecting causes with a predicate * @see {@link catchFilter} for selecting typed errors with a `Filter` * @see {@link catchCause} for recovering from every cause * * @stability stable * @category error handling * @since 4.0.0 */ export declare const catchCauseFilter: { /** * Recovers from channel failures whose full `Cause` is selected by a `Filter`. * * **When to use** * * Use when you need to recover a channel only from causes selected by a * `Filter`, while giving the recovery both the selected value and the original * `Cause`. * * **Details** * * When the filter succeeds, the recovery function receives the selected value * and the original cause. When the filter fails, the returned channel fails * with the residual cause produced by the filter. * * @see {@link catchCauseIf} for selecting causes with a predicate * @see {@link catchFilter} for selecting typed errors with a `Filter` * @see {@link catchCause} for recovering from every cause * * @stability stable * @category error handling * @since 4.0.0 */ , OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1>(filter: Filter.Filter, EB, X>, f: (failure: EB, cause: Cause.Cause) => Channel): (self: Channel) => Channel | OutErr1, OutDone | OutDone1, InElem & InElem1, InErr & InErr1, InDone & InDone1, Env | Env1>; /** * Recovers from channel failures whose full `Cause` is selected by a `Filter`. * * **When to use** * * Use when you need to recover a channel only from causes selected by a * `Filter`, while giving the recovery both the selected value and the original * `Cause`. * * **Details** * * When the filter succeeds, the recovery function receives the selected value * and the original cause. When the filter fails, the returned channel fails * with the residual cause produced by the filter. * * @see {@link catchCauseIf} for selecting causes with a predicate * @see {@link catchFilter} for selecting typed errors with a `Filter` * @see {@link catchCause} for recovering from every cause * * @stability stable * @category error handling * @since 4.0.0 */ , OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1>(self: Channel, filter: Filter.Filter, EB, X>, f: (failure: EB, cause: Cause.Cause) => Channel): Channel | OutErr1, OutDone | OutDone1, InElem & InElem1, InErr & InErr1, InDone & InDone1, Env | Env1>; }; declare const catch_: { (f: (d: OutErr) => Channel): (self: Channel) => Channel; (self: Channel, f: (d: OutErr) => Channel): Channel; }; export { /** * Recovers from typed channel errors by running a fallback channel. * * **Gotchas** * * Defects take precedence over typed errors. If the cause also contains a * defect, the handler does not run and the failure is propagated with every * typed error converted to a defect. An interruption alongside a typed error * does not prevent recovery. * * @stability stable * @category error handling * @since 4.0.0 */ 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. * * @stability stable * @category error handling * @since 4.0.0 */ export declare const tapError: { /** * Runs an effect when the channel fails with a typed error, then preserves the * original channel failure. * * **Details** * * The effect is not run for normal channel completion. If the observer effect * fails, that failure can fail the returned channel. * * @stability stable * @category error handling * @since 4.0.0 */ (f: (d: OutErr) => Effect.Effect): (self: Channel) => Channel; /** * Runs an effect when the channel fails with a typed error, then preserves the * original channel failure. * * **Details** * * The effect is not run for normal channel completion. If the observer effect * fails, that failure can fail the returned channel. * * @stability stable * @category error handling * @since 4.0.0 */ (self: Channel, f: (d: OutErr) => Effect.Effect): Channel; }; /** * Recovers from typed channel errors that match a predicate or refinement. * * **When to use** * * Use to recover from typed channel errors when a predicate or refinement * selects the failures that should switch to a recovery channel. * * **Details** * * Matching errors are handled by the recovery function. Non-matching errors * are handled by `orElse` when provided. Without `orElse`, non-matching errors * are re-failed. * * **Gotchas** * * If the cause contains a defect, the handler is skipped and every typed error * is converted to a defect, preserving reason order and interrupts. An * interruption alongside a typed error does not prevent recovery. * * @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` * * @stability stable * @category error handling * @since 4.0.0 */ export declare const catchIf: { /** * Recovers from typed channel errors that match a predicate or refinement. * * **When to use** * * Use to recover from typed channel errors when a predicate or refinement * selects the failures that should switch to a recovery channel. * * **Details** * * Matching errors are handled by the recovery function. Non-matching errors * are handled by `orElse` when provided. Without `orElse`, non-matching errors * are re-failed. * * **Gotchas** * * If the cause contains a defect, the handler is skipped and every typed error * is converted to a defect, preserving reason order and interrupts. An * interruption alongside a typed error does not prevent recovery. * * @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` * * @stability stable * @category error handling * @since 4.0.0 */ (refinement: Predicate.Refinement, EB>, f: (failure: EB) => Channel, orElse?: ((failure: Exclude) => Channel) | undefined): (self: Channel) => Channel, OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? Exclude : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; /** * Recovers from typed channel errors that match a predicate or refinement. * * **When to use** * * Use to recover from typed channel errors when a predicate or refinement * selects the failures that should switch to a recovery channel. * * **Details** * * Matching errors are handled by the recovery function. Non-matching errors * are handled by `orElse` when provided. Without `orElse`, non-matching errors * are re-failed. * * **Gotchas** * * If the cause contains a defect, the handler is skipped and every typed error * is converted to a defect, preserving reason order and interrupts. An * interruption alongside a typed error does not prevent recovery. * * @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` * * @stability stable * @category error handling * @since 4.0.0 */ (predicate: Predicate.Predicate, f: (failure: OutErr) => Channel, orElse?: ((failure: OutErr) => Channel) | undefined): (self: Channel) => Channel, OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? OutErr : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; /** * Recovers from typed channel errors that match a predicate or refinement. * * **When to use** * * Use to recover from typed channel errors when a predicate or refinement * selects the failures that should switch to a recovery channel. * * **Details** * * Matching errors are handled by the recovery function. Non-matching errors * are handled by `orElse` when provided. Without `orElse`, non-matching errors * are re-failed. * * **Gotchas** * * If the cause contains a defect, the handler is skipped and every typed error * is converted to a defect, preserving reason order and interrupts. An * interruption alongside a typed error does not prevent recovery. * * @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` * * @stability stable * @category error handling * @since 4.0.0 */ (self: Channel, refinement: Predicate.Refinement, EB>, f: (failure: EB) => Channel, orElse?: ((failure: Exclude) => Channel) | undefined): Channel, OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? Exclude : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; /** * Recovers from typed channel errors that match a predicate or refinement. * * **When to use** * * Use to recover from typed channel errors when a predicate or refinement * selects the failures that should switch to a recovery channel. * * **Details** * * Matching errors are handled by the recovery function. Non-matching errors * are handled by `orElse` when provided. Without `orElse`, non-matching errors * are re-failed. * * **Gotchas** * * If the cause contains a defect, the handler is skipped and every typed error * is converted to a defect, preserving reason order and interrupts. An * interruption alongside a typed error does not prevent recovery. * * @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` * * @stability stable * @category error handling * @since 4.0.0 */ (self: Channel, predicate: Predicate.Predicate, f: (failure: OutErr) => Channel, orElse?: ((failure: OutErr) => Channel) | undefined): Channel, OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? OutErr : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; }; /** * Recovers from typed channel errors selected by a `Filter`. * * **When to use** * * Use to recover from channel errors with a reusable `Filter` when matching * can also narrow or transform the error before choosing the recovery channel. * * **Details** * * Successful filter results are handled by the recovery function. Failed * filter results are handled by `orElse` when provided. Without `orElse`, * failed filter results are re-failed. * * **Gotchas** * * If the cause contains a defect, the handler is skipped and every typed error * is converted to a defect, preserving reason order and interrupts. An * interruption alongside a typed error does not prevent recovery. * * @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` * * @stability stable * @category error handling * @since 4.0.0 */ export declare const catchFilter: { /** * Recovers from typed channel errors selected by a `Filter`. * * **When to use** * * Use to recover from channel errors with a reusable `Filter` when matching * can also narrow or transform the error before choosing the recovery channel. * * **Details** * * Successful filter results are handled by the recovery function. Failed * filter results are handled by `orElse` when provided. Without `orElse`, * failed filter results are re-failed. * * **Gotchas** * * If the cause contains a defect, the handler is skipped and every typed error * is converted to a defect, preserving reason order and interrupts. An * interruption alongside a typed error does not prevent recovery. * * @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` * * @stability stable * @category error handling * @since 4.0.0 */ (filter: Filter.Filter, f: (failure: EB) => Channel, orElse?: ((failure: X) => Channel) | undefined): (self: Channel) => Channel, OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? X : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; /** * Recovers from typed channel errors selected by a `Filter`. * * **When to use** * * Use to recover from channel errors with a reusable `Filter` when matching * can also narrow or transform the error before choosing the recovery channel. * * **Details** * * Successful filter results are handled by the recovery function. Failed * filter results are handled by `orElse` when provided. Without `orElse`, * failed filter results are re-failed. * * **Gotchas** * * If the cause contains a defect, the handler is skipped and every typed error * is converted to a defect, preserving reason order and interrupts. An * interruption alongside a typed error does not prevent recovery. * * @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` * * @stability stable * @category error handling * @since 4.0.0 */ (self: Channel, filter: Filter.Filter, f: (failure: EB) => Channel, orElse?: ((failure: X) => Channel) | undefined): Channel, OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? X : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; }; /** * Recovers from tagged channel errors whose `_tag` matches one or more tags. * * **Details** * * Matching tagged errors are handled by the recovery function. Non-matching * errors are handled by `orElse` when provided. Without `orElse`, * non-matching errors are re-failed. * * **Gotchas** * * If the cause contains a defect, the handler is skipped and every typed error * is converted to a defect, preserving reason order and interrupts. An * interruption alongside a typed error does not prevent recovery. * * @stability stable * @category error handling * @since 4.0.0 */ export declare const catchTag: { /** * Recovers from tagged channel errors whose `_tag` matches one or more tags. * * **Details** * * Matching tagged errors are handled by the recovery function. Non-matching * errors are handled by `orElse` when provided. Without `orElse`, * non-matching errors are re-failed. * * **Gotchas** * * If the cause contains a defect, the handler is skipped and every typed error * is converted to a defect, preserving reason order and interrupts. An * interruption alongside a typed error does not prevent recovery. * * @stability stable * @category error handling * @since 4.0.0 */ | Arr.NonEmptyReadonlyArray>, OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1, OutElem2 = Types.unassigned, OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, InDone2 = unknown, Env2 = never>(k: K, f: (e: Types.ExtractTag, K extends Arr.NonEmptyReadonlyArray ? K[number] : K>) => Channel, orElse?: ((e: Types.ExcludeTag, K extends Arr.NonEmptyReadonlyArray ? K[number] : K>) => Channel) | undefined): (self: Channel) => Channel, OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? Types.ExcludeTag ? K[number] : K> : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; /** * Recovers from tagged channel errors whose `_tag` matches one or more tags. * * **Details** * * Matching tagged errors are handled by the recovery function. Non-matching * errors are handled by `orElse` when provided. Without `orElse`, * non-matching errors are re-failed. * * **Gotchas** * * If the cause contains a defect, the handler is skipped and every typed error * is converted to a defect, preserving reason order and interrupts. An * interruption alongside a typed error does not prevent recovery. * * @stability stable * @category error handling * @since 4.0.0 */ | Arr.NonEmptyReadonlyArray>, OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1, OutElem2 = Types.unassigned, OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, InDone2 = unknown, Env2 = never>(self: Channel, k: K, f: (e: Types.ExtractTag, K extends Arr.NonEmptyReadonlyArray ? K[number] : K>) => Channel, orElse?: ((e: Types.ExcludeTag, K extends Arr.NonEmptyReadonlyArray ? K[number] : K>) => Channel) | undefined): Channel, OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? Types.ExcludeTag ? K[number] : K> : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; }; /** * Catches a specific reason within a tagged error. * * **Gotchas** * * If the cause contains a defect, the handler is skipped and every typed error * is converted to a defect, preserving reason order and interrupts. An * interruption alongside a typed error does not prevent recovery. * * **Example** (Recovering from nested reasons) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class RateLimitError extends Data.TaggedError("RateLimitError")<{ * retryAfter: number * }> {} * * class QuotaExceededError extends Data.TaggedError("QuotaExceededError")<{ * limit: number * }> {} * * class AiError extends Data.TaggedError("AiError")<{ * reason: RateLimitError | QuotaExceededError * }> {} * * const reason = new RateLimitError({ retryAfter: 60 }) * const channel = Channel.fail(new AiError({ reason })) * * const recovered = channel.pipe( * Channel.catchReason("AiError", "RateLimitError", (reason) => * Channel.succeed(`retry: ${reason.retryAfter}`) * ) * ) * Effect.runSync(Channel.runCollect(recovered)) // => ["retry: 60"] * ``` * * @stability stable * @category error handling * @since 4.0.0 */ export declare const catchReason: { /** * Catches a specific reason within a tagged error. * * **Gotchas** * * If the cause contains a defect, the handler is skipped and every typed error * is converted to a defect, preserving reason order and interrupts. An * interruption alongside a typed error does not prevent recovery. * * **Example** (Recovering from nested reasons) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class RateLimitError extends Data.TaggedError("RateLimitError")<{ * retryAfter: number * }> {} * * class QuotaExceededError extends Data.TaggedError("QuotaExceededError")<{ * limit: number * }> {} * * class AiError extends Data.TaggedError("AiError")<{ * reason: RateLimitError | QuotaExceededError * }> {} * * const reason = new RateLimitError({ retryAfter: 60 }) * const channel = Channel.fail(new AiError({ reason })) * * const recovered = channel.pipe( * Channel.catchReason("AiError", "RateLimitError", (reason) => * Channel.succeed(`retry: ${reason.retryAfter}`) * ) * ) * Effect.runSync(Channel.runCollect(recovered)) // => ["retry: 60"] * ``` * * @stability stable * @category error handling * @since 4.0.0 */ , RK extends Types.ReasonTags, K>>, OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1, OutElem2 = Types.unassigned, OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, InDone2 = unknown, Env2 = never>(errorTag: K, reasonTag: RK, f: (reason: Types.ExtractReason, K>, RK>, error: Types.NarrowReason, K>, RK>) => Channel, orElse?: ((reason: Types.ExcludeReason, K>, RK>, error: Types.OmitReason, K>, RK>) => Channel) | undefined): (self: Channel) => Channel, Types.ExcludeTag | OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? Types.ExtractTag : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; /** * Catches a specific reason within a tagged error. * * **Gotchas** * * If the cause contains a defect, the handler is skipped and every typed error * is converted to a defect, preserving reason order and interrupts. An * interruption alongside a typed error does not prevent recovery. * * **Example** (Recovering from nested reasons) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class RateLimitError extends Data.TaggedError("RateLimitError")<{ * retryAfter: number * }> {} * * class QuotaExceededError extends Data.TaggedError("QuotaExceededError")<{ * limit: number * }> {} * * class AiError extends Data.TaggedError("AiError")<{ * reason: RateLimitError | QuotaExceededError * }> {} * * const reason = new RateLimitError({ retryAfter: 60 }) * const channel = Channel.fail(new AiError({ reason })) * * const recovered = channel.pipe( * Channel.catchReason("AiError", "RateLimitError", (reason) => * Channel.succeed(`retry: ${reason.retryAfter}`) * ) * ) * Effect.runSync(Channel.runCollect(recovered)) // => ["retry: 60"] * ``` * * @stability stable * @category error handling * @since 4.0.0 */ , RK extends Types.ReasonTags, K>>, OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1, OutElem2 = Types.unassigned, OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, InDone2 = unknown, Env2 = never>(self: Channel, errorTag: K, reasonTag: RK, f: (reason: Types.ExtractReason, K>, RK>, error: Types.NarrowReason, K>, RK>) => Channel, orElse?: ((reason: Types.ExcludeReason, K>, RK>, error: Types.OmitReason, K>, RK>) => Channel) | undefined): Channel, Types.ExcludeTag | OutErr1 | OutErr2 | (OutElem2 extends Types.unassigned ? Types.ExtractTag : never), OutDone | OutDone1 | OutDone2, InElem & InElem1 & InElem2, InErr & InErr1 & InErr2, InDone & InDone1 & InDone2, Env | Env1 | Env2>; }; /** * Catches multiple reasons within a tagged error using an object of handlers. * * **Gotchas** * * If the cause contains a defect, the handler is skipped and every typed error * is converted to a defect, preserving reason order and interrupts. An * interruption alongside a typed error does not prevent recovery. * * @stability stable * @category error handling * @since 4.0.0 */ export declare const catchReasons: { /** * Catches multiple reasons within a tagged error using an object of handlers. * * **Gotchas** * * If the cause contains a defect, the handler is skipped and every typed error * is converted to a defect, preserving reason order and interrupts. An * interruption alongside a typed error does not prevent recovery. * * @stability stable * @category error handling * @since 4.0.0 */ , OutErr, Cases extends { [RK in Types.ReasonTags, K>>]+?: (reason: Types.ExtractReason, K>, RK>, error: Types.NarrowReason, K>, RK>) => Channel; }, OutElem2 = Types.unassigned, OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, InDone2 = unknown, Env2 = never>(errorTag: K, cases: Cases, orElse?: ((reason: Types.ExcludeReason, K>, Extract>, error: Types.OmitReason, K>, Extract>) => Channel) | undefined): (self: Channel) => Channel | { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? OutElem1 : never; }[keyof Cases], Types.ExcludeTag | OutErr2 | (OutElem2 extends Types.unassigned ? Types.ExtractTag : never) | { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? OutErr1 : never; }[keyof Cases], OutDone | OutDone2 | { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? OutDone1 : never; }[keyof Cases], InElem & InElem2 & { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? InElem1 : never; }[keyof Cases], InErr & InErr2 & { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? InErr1 : never; }[keyof Cases], InDone & InDone2 & { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? InDone1 : never; }[keyof Cases], Env | Env2 | { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? Env1 : never; }[keyof Cases]>; /** * Catches multiple reasons within a tagged error using an object of handlers. * * **Gotchas** * * If the cause contains a defect, the handler is skipped and every typed error * is converted to a defect, preserving reason order and interrupts. An * interruption alongside a typed error does not prevent recovery. * * @stability stable * @category error handling * @since 4.0.0 */ , Cases extends { [RK in Types.ReasonTags>]+?: (reason: Types.ExtractReason, RK>, error: Types.NarrowReason, RK>) => Channel; }, OutElem2 = Types.unassigned, OutErr2 = never, OutDone2 = never, InElem2 = unknown, InErr2 = unknown, InDone2 = unknown, Env2 = never>(self: Channel, errorTag: K, cases: Cases, orElse?: ((reason: Types.ExcludeReason, K>, Extract>, error: Types.OmitReason, K>, Extract>) => Channel) | undefined): Channel | { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? OutElem1 : never; }[keyof Cases], Types.ExcludeTag | OutErr2 | (OutElem2 extends Types.unassigned ? Types.ExtractTag : never) | { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? OutErr1 : never; }[keyof Cases], OutDone | OutDone2 | { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? OutDone1 : never; }[keyof Cases], InElem & InElem2 & { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? InElem1 : never; }[keyof Cases], InErr & InErr2 & { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? InErr1 : never; }[keyof Cases], InDone & InDone2 & { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? InDone1 : never; }[keyof Cases], Env | Env2 | { [RK in keyof Cases]: Cases[RK] extends (...args: Array) => Channel ? Env1 : never; }[keyof Cases]>; }; /** * Promotes nested reason errors into the channel error, replacing the parent error. * * **Example** (Promoting nested reasons) * * ```ts import.meta.vitest * import { Channel, Data, Effect, Exit } from "effect" * * class RateLimitError extends Data.TaggedError("RateLimitError")<{ * retryAfter: number * }> {} * * class QuotaExceededError extends Data.TaggedError("QuotaExceededError")<{ * limit: number * }> {} * * class AiError extends Data.TaggedError("AiError")<{ * reason: RateLimitError | QuotaExceededError * }> {} * * const reason = new RateLimitError({ retryAfter: 60 }) * const channel = Channel.fail(new AiError({ reason })) * * const unwrapped = channel.pipe(Channel.unwrapReason("AiError")) * Effect.runSync(Effect.exit(Channel.runCollect(unwrapped))) // => Exit.fail(reason) * ``` * * @stability stable * @category error handling * @since 4.0.0 */ export declare const unwrapReason: { /** * Promotes nested reason errors into the channel error, replacing the parent error. * * **Example** (Promoting nested reasons) * * ```ts import.meta.vitest * import { Channel, Data, Effect, Exit } from "effect" * * class RateLimitError extends Data.TaggedError("RateLimitError")<{ * retryAfter: number * }> {} * * class QuotaExceededError extends Data.TaggedError("QuotaExceededError")<{ * limit: number * }> {} * * class AiError extends Data.TaggedError("AiError")<{ * reason: RateLimitError | QuotaExceededError * }> {} * * const reason = new RateLimitError({ retryAfter: 60 }) * const channel = Channel.fail(new AiError({ reason })) * * const unwrapped = channel.pipe(Channel.unwrapReason("AiError")) * Effect.runSync(Effect.exit(Channel.runCollect(unwrapped))) // => Exit.fail(reason) * ``` * * @stability stable * @category error handling * @since 4.0.0 */ , OutErr>(errorTag: K): (self: Channel) => Channel | Types.ReasonOf>, OutDone, InElem, InErr, InDone, Env>; /** * Promotes nested reason errors into the channel error, replacing the parent error. * * **Example** (Promoting nested reasons) * * ```ts import.meta.vitest * import { Channel, Data, Effect, Exit } from "effect" * * class RateLimitError extends Data.TaggedError("RateLimitError")<{ * retryAfter: number * }> {} * * class QuotaExceededError extends Data.TaggedError("QuotaExceededError")<{ * limit: number * }> {} * * class AiError extends Data.TaggedError("AiError")<{ * reason: RateLimitError | QuotaExceededError * }> {} * * const reason = new RateLimitError({ retryAfter: 60 }) * const channel = Channel.fail(new AiError({ reason })) * * const unwrapped = channel.pipe(Channel.unwrapReason("AiError")) * Effect.runSync(Effect.exit(Channel.runCollect(unwrapped))) // => Exit.fail(reason) * ``` * * @stability stable * @category error handling * @since 4.0.0 */ >(self: Channel, errorTag: K): Channel | Types.ReasonOf>, OutDone, InElem, InErr, InDone, Env>; }; /** * Transforms the typed errors of a channel using the specified function. * * **Details** * * Maps every typed error in the cause, preserving defects, interrupts and * reason order. Unlike typed recovery, mapping does not convert errors to defects. * * @stability stable * @category error handling * @since 2.0.0 */ export declare const mapError: { /** * Transforms the typed errors of a channel using the specified function. * * **Details** * * Maps every typed error in the cause, preserving defects, interrupts and * reason order. Unlike typed recovery, mapping does not convert errors to defects. * * @stability stable * @category error handling * @since 2.0.0 */ (f: (err: OutErr) => OutErr2): (self: Channel) => Channel; /** * Transforms the typed errors of a channel using the specified function. * * **Details** * * Maps every typed error in the cause, preserving defects, interrupts and * reason order. Unlike typed recovery, mapping does not convert errors to defects. * * @stability stable * @category error handling * @since 2.0.0 */ (self: Channel, f: (err: OutErr) => OutErr2): Channel; }; /** * Converts all errors in the channel to defects (unrecoverable failures). * This is useful when you want to treat errors as programming errors. * * **Example** (Converting failures to defects) * * ```ts import.meta.vitest * import { Cause, Channel, Data, Effect, Exit } from "effect" * * class ValidationError extends Data.TaggedError("ValidationError")<{ * readonly field: string * }> {} * * // Create a channel that might fail * const error = new ValidationError({ field: "email" }) * const failingChannel = Channel.fail(error) * * // Convert failures to defects * const fatalChannel = Channel.orDie(failingChannel) * * Effect.runSync(Effect.exit(Channel.runCollect(fatalChannel))) // => Exit.failCause(Cause.die(error)) * ``` * * @stability stable * @category error handling * @since 2.0.0 */ export declare const orDie: (self: Channel) => Channel; /** * Ignores all errors in the channel, converting them to an empty channel. * * **Details** * * Use the `log` option to emit the full {@link Cause} when the channel fails. * * **Gotchas** * * Defects take precedence over typed errors. If the cause also contains a * defect, the failure is not ignored and is propagated with every typed error * converted to a defect. An interruption alongside a typed error does not * prevent the error from being ignored. * * @stability stable * @category error handling * @since 4.0.0 */ export declare const ignore: | { readonly log?: boolean | Severity | undefined; } | undefined = { readonly log?: boolean | Severity | undefined; }>(selfOrOptions: Arg, options?: { readonly log?: boolean | Severity | undefined; } | undefined) => [Arg] extends [ Channel ] ? Channel : (self: Channel) => Channel; /** * 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. * * @stability stable * @category error handling * @since 4.0.0 */ export declare const ignoreCause: | { readonly log?: boolean | Severity | undefined; } | undefined = { readonly log?: boolean | Severity | undefined; }>(selfOrOptions: Arg, options?: { readonly log?: boolean | Severity | undefined; } | undefined) => [Arg] extends [ Channel ] ? Channel : (self: Channel) => Channel; /** * Returns a new channel that retries this channel according to the specified * schedule whenever it fails. * * **Gotchas** * * Defects take precedence over typed errors. A failure whose cause contains a * defect is not retried and is propagated with every typed error converted to a * defect. A typed error alongside an interruption is retried. * * @stability stable * @category error handling * @since 4.0.0 */ export declare const retry: { /** * Returns a new channel that retries this channel according to the specified * schedule whenever it fails. * * **Gotchas** * * Defects take precedence over typed errors. A failure whose cause contains a * defect is not retried and is propagated with every typed error converted to a * defect. A typed error alongside an interruption is retried. * * @stability stable * @category error handling * @since 4.0.0 */ (schedule: Schedule.Schedule, SE, SR> | (($: (_: Schedule.Schedule, SE, SR>) => Schedule.Schedule) => Schedule.Schedule, SE, SR>)): (self: Channel) => Channel; /** * Returns a new channel that retries this channel according to the specified * schedule whenever it fails. * * **Gotchas** * * Defects take precedence over typed errors. A failure whose cause contains a * defect is not retried and is propagated with every typed error converted to a * defect. A typed error alongside an interruption is retried. * * @stability stable * @category error handling * @since 4.0.0 */ (self: Channel, schedule: Schedule.Schedule | (($: (_: Schedule.Schedule, SE, SR>) => Schedule.Schedule) => Schedule.Schedule, SE, SR>)): Channel; }; /** * 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) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class SwitchError extends Data.TaggedError("SwitchError")<{ * readonly reason: string * }> {} * * // Create a channel that outputs numbers * const numberChannel = Channel.fromIterable([1, 2, 3]) * * // Switch to new channels based on each value * const switchedChannel = Channel.switchMap( * numberChannel, * (n) => Channel.fromIterable([`value-${n}`]) * ) * * await Effect.runPromise(Channel.runCollect(switchedChannel)) // => ["value-3"] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ export declare const switchMap: { /** * 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) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class SwitchError extends Data.TaggedError("SwitchError")<{ * readonly reason: string * }> {} * * // Create a channel that outputs numbers * const numberChannel = Channel.fromIterable([1, 2, 3]) * * // Switch to new channels based on each value * const switchedChannel = Channel.switchMap( * numberChannel, * (n) => Channel.fromIterable([`value-${n}`]) * ) * * await Effect.runPromise(Channel.runCollect(switchedChannel)) // => ["value-3"] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ (f: (d: OutElem) => Channel, options?: { readonly concurrency?: Types.Concurrency | undefined; readonly bufferSize?: number | undefined; }): (self: Channel) => Channel; /** * 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) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class SwitchError extends Data.TaggedError("SwitchError")<{ * readonly reason: string * }> {} * * // Create a channel that outputs numbers * const numberChannel = Channel.fromIterable([1, 2, 3]) * * // Switch to new channels based on each value * const switchedChannel = Channel.switchMap( * numberChannel, * (n) => Channel.fromIterable([`value-${n}`]) * ) * * await Effect.runPromise(Channel.runCollect(switchedChannel)) // => ["value-3"] * ``` * * @stability stable * @category sequencing * @since 4.0.0 */ (self: Channel, f: (d: OutElem) => Channel, options?: { readonly concurrency?: Types.Concurrency | undefined; readonly bufferSize?: number | undefined; }): Channel; }; /** * Merges multiple channels with specified concurrency and buffering options. * * **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.meta.vitest * import { Channel, Data, Effect } from "effect" * * class MergeAllError extends Data.TaggedError("MergeAllError")<{ * readonly reason: string * }> {} * * // Create channels that output other channels * const nestedChannels = Channel.fromIterable([ * Channel.fromIterable([1, 2]), * Channel.fromIterable([3, 4]), * Channel.fromIterable([5, 6]) * ]) * * // Merge all channels with bounded concurrency * const mergedChannel = Channel.mergeAll({ * concurrency: 1, * bufferSize: 16 * })(nestedChannels) * * await Effect.runPromise(Channel.runCollect(mergedChannel)) // => [1, 2, 3, 4, 5, 6] * ``` * * @stability stable * @category combining * @since 2.0.0 */ export declare const mergeAll: { /** * Merges multiple channels with specified concurrency and buffering options. * * **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.meta.vitest * import { Channel, Data, Effect } from "effect" * * class MergeAllError extends Data.TaggedError("MergeAllError")<{ * readonly reason: string * }> {} * * // Create channels that output other channels * const nestedChannels = Channel.fromIterable([ * Channel.fromIterable([1, 2]), * Channel.fromIterable([3, 4]), * Channel.fromIterable([5, 6]) * ]) * * // Merge all channels with bounded concurrency * const mergedChannel = Channel.mergeAll({ * concurrency: 1, * bufferSize: 16 * })(nestedChannels) * * await Effect.runPromise(Channel.runCollect(mergedChannel)) // => [1, 2, 3, 4, 5, 6] * ``` * * @stability stable * @category combining * @since 2.0.0 */ (options: { readonly concurrency: Types.Concurrency; readonly bufferSize?: number | undefined; readonly switch?: boolean | undefined; }): (channels: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>) => Channel; /** * Merges multiple channels with specified concurrency and buffering options. * * **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.meta.vitest * import { Channel, Data, Effect } from "effect" * * class MergeAllError extends Data.TaggedError("MergeAllError")<{ * readonly reason: string * }> {} * * // Create channels that output other channels * const nestedChannels = Channel.fromIterable([ * Channel.fromIterable([1, 2]), * Channel.fromIterable([3, 4]), * Channel.fromIterable([5, 6]) * ]) * * // Merge all channels with bounded concurrency * const mergedChannel = Channel.mergeAll({ * concurrency: 1, * bufferSize: 16 * })(nestedChannels) * * await Effect.runPromise(Channel.runCollect(mergedChannel)) // => [1, 2, 3, 4, 5, 6] * ``` * * @stability stable * @category combining * @since 2.0.0 */ (channels: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>, options: { readonly concurrency: Types.Concurrency; readonly bufferSize?: number | undefined; readonly switch?: boolean | undefined; }): Channel; }; /** * Represents strategies for halting merged channels when one completes or fails. * * **Example** (Choosing merge halt strategies) * * ```ts import.meta.vitest * import { Channel } from "effect" * * // Different halt strategies for channel merging * const strategies: Array = ["left", "right", "both", "either"] // => ["left", "right", "both", "either"] * ``` * * @stability stable * @category models * @since 4.0.0 */ export type HaltStrategy = "left" | "right" | "both" | "either"; /** * Returns a new channel, which is the merge of this channel and the specified * channel. * * **Example** (Merging channels) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // Create two channels * const leftChannel = Channel.fromIterable([1, 2, 3]) * const rightChannel = Channel.fromIterable(["a", "b", "c"]) * * // The default "both" strategy waits for both channels to complete * const mergedChannel = Channel.merge(leftChannel, rightChannel) * * const values = await Effect.runPromise(Channel.runCollect(mergedChannel)) * values.map(String).sort() // => ["1", "2", "3", "a", "b", "c"] * ``` * * @stability stable * @category combining * @since 4.0.0 */ export declare const merge: { /** * Returns a new channel, which is the merge of this channel and the specified * channel. * * **Example** (Merging channels) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // Create two channels * const leftChannel = Channel.fromIterable([1, 2, 3]) * const rightChannel = Channel.fromIterable(["a", "b", "c"]) * * // The default "both" strategy waits for both channels to complete * const mergedChannel = Channel.merge(leftChannel, rightChannel) * * const values = await Effect.runPromise(Channel.runCollect(mergedChannel)) * values.map(String).sort() // => ["1", "2", "3", "a", "b", "c"] * ``` * * @stability stable * @category combining * @since 4.0.0 */ (right: Channel, options?: { readonly haltStrategy?: HaltStrategy | undefined; } | undefined): (left: Channel) => Channel; /** * Returns a new channel, which is the merge of this channel and the specified * channel. * * **Example** (Merging channels) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * // Create two channels * const leftChannel = Channel.fromIterable([1, 2, 3]) * const rightChannel = Channel.fromIterable(["a", "b", "c"]) * * // The default "both" strategy waits for both channels to complete * const mergedChannel = Channel.merge(leftChannel, rightChannel) * * const values = await Effect.runPromise(Channel.runCollect(mergedChannel)) * values.map(String).sort() // => ["1", "2", "3", "a", "b", "c"] * ``` * * @stability stable * @category combining * @since 4.0.0 */ (left: Channel, right: Channel, options?: { readonly haltStrategy?: HaltStrategy | undefined; } | undefined): Channel; }; /** * Runs an effect concurrently with a channel while emitting only the channel's * output elements. * * **When to use** * * Use when a side effect should run for the lifetime of a channel and only the * channel's output elements should be emitted. * * **Details** * * The effect's successful value is ignored. If the effect fails while the * channel is running, the returned channel fails with that error. * * @stability stable * @category combining * @since 4.0.0 */ export declare const mergeEffect: { /** * Runs an effect concurrently with a channel while emitting only the channel's * output elements. * * **When to use** * * Use when a side effect should run for the lifetime of a channel and only the * channel's output elements should be emitted. * * **Details** * * The effect's successful value is ignored. If the effect fails while the * channel is running, the returned channel fails with that error. * * @stability stable * @category combining * @since 4.0.0 */ (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. * * @stability stable * @category combining * @since 4.0.0 */ (self: Channel, effect: Effect.Effect): Channel; }; /** * Splits upstream string chunks into lines, recognizing `\n`, `\r\n`, and * 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** (Splitting string chunks into lines) * * ```ts import.meta.vitest * import { Effect, Stream } from "effect" * * const result = await Effect.runPromise(Stream.runCollect( * Stream.splitLines(Stream.make("hel", "lo\r\nwor", "ld\n")) * )) * result // => ["hello", "world"] * ``` * * @stability stable * @category splitting * @since 2.0.0 */ export declare const splitLines: () => Channel, Err, Done, Arr.NonEmptyReadonlyArray, Err, Done>; /** * Decodes incoming `Uint8Array` chunks into strings using `TextDecoder`. * * **Details** * * Input chunks are decoded with streaming enabled so multi-byte characters may * span `Uint8Array` boundaries. On normal completion, incomplete trailing * characters become U+FFFD or, with `fatal: true`, a defect. The optional * `encoding` and `options` are passed to `TextDecoder`. * * @stability stable * @category decoding * @since 4.0.0 */ export declare const decodeText: (encoding?: string, options?: ConstructorParameters[1]) => Channel, Err, Done, Arr.NonEmptyReadonlyArray, Err, Done>; /** * Encodes incoming string chunks into `Uint8Array` values using `TextEncoder`. * * **Details** * * Each string inside an emitted array is encoded independently. * * @stability stable * @category encoding * @since 4.0.0 */ export declare const encodeText: () => Channel, Err, Done, Arr.NonEmptyReadonlyArray, Err, Done>; /** * Returns a new channel that pipes the output of this channel into the * specified channel. The returned channel has the input type of this channel, * and the output type of the specified channel, terminating with the value of * the specified channel. * * **Example** (Piping one channel into another) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class PipeError extends Data.TaggedError("PipeError")<{ * readonly stage: string * }> {} * * // Create source and transform channels * const sourceChannel = Channel.fromIterable([1, 2, 3]) * const transformChannel = Channel.map(sourceChannel, (n: number) => n * 2) * * // Pipe the source into the transform * const pipedChannel = Channel.pipeTo(sourceChannel, transformChannel) * * Effect.runSync(Channel.runCollect(pipedChannel)) // => [2, 4, 6] * ``` * * @stability stable * @category sequencing * @since 2.0.0 */ export declare const pipeTo: { /** * Returns a new channel that pipes the output of this channel into the * specified channel. The returned channel has the input type of this channel, * and the output type of the specified channel, terminating with the value of * the specified channel. * * **Example** (Piping one channel into another) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class PipeError extends Data.TaggedError("PipeError")<{ * readonly stage: string * }> {} * * // Create source and transform channels * const sourceChannel = Channel.fromIterable([1, 2, 3]) * const transformChannel = Channel.map(sourceChannel, (n: number) => n * 2) * * // Pipe the source into the transform * const pipedChannel = Channel.pipeTo(sourceChannel, transformChannel) * * Effect.runSync(Channel.runCollect(pipedChannel)) // => [2, 4, 6] * ``` * * @stability stable * @category sequencing * @since 2.0.0 */ (that: Channel): (self: Channel) => Channel; /** * Returns a new channel that pipes the output of this channel into the * specified channel. The returned channel has the input type of this channel, * and the output type of the specified channel, terminating with the value of * the specified channel. * * **Example** (Piping one channel into another) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class PipeError extends Data.TaggedError("PipeError")<{ * readonly stage: string * }> {} * * // Create source and transform channels * const sourceChannel = Channel.fromIterable([1, 2, 3]) * const transformChannel = Channel.map(sourceChannel, (n: number) => n * 2) * * // Pipe the source into the transform * const pipedChannel = Channel.pipeTo(sourceChannel, transformChannel) * * Effect.runSync(Channel.runCollect(pipedChannel)) // => [2, 4, 6] * ``` * * @stability stable * @category sequencing * @since 2.0.0 */ (self: Channel, that: Channel): Channel; }; /** * Returns a new channel that pipes the output of this channel into the * specified channel and preserves this channel's failures without providing * them to the other channel for observation. * * **Example** (Piping while preserving failures) * * ```ts import.meta.vitest * import { Channel, Data, Effect, Exit } from "effect" * * class SourceError extends Data.TaggedError("SourceError")<{ * readonly code: number * }> {} * * // Create a failing source channel * const error = new SourceError({ code: 404 }) * const failingSource = Channel.fail(error) * const safeTransform = Channel.identity() * * // Pipe while preserving source failures * const safePipedChannel = Channel.pipeToOrFail(failingSource, safeTransform) * * Effect.runSync(Effect.exit(Channel.runCollect(safePipedChannel))) // => Exit.fail(error) * ``` * * @stability stable * @category sequencing * @since 2.0.0 */ export declare const pipeToOrFail: { /** * Returns a new channel that pipes the output of this channel into the * specified channel and preserves this channel's failures without providing * them to the other channel for observation. * * **Example** (Piping while preserving failures) * * ```ts import.meta.vitest * import { Channel, Data, Effect, Exit } from "effect" * * class SourceError extends Data.TaggedError("SourceError")<{ * readonly code: number * }> {} * * // Create a failing source channel * const error = new SourceError({ code: 404 }) * const failingSource = Channel.fail(error) * const safeTransform = Channel.identity() * * // Pipe while preserving source failures * const safePipedChannel = Channel.pipeToOrFail(failingSource, safeTransform) * * Effect.runSync(Effect.exit(Channel.runCollect(safePipedChannel))) // => Exit.fail(error) * ``` * * @stability stable * @category sequencing * @since 2.0.0 */ (that: Channel): (self: Channel) => Channel; /** * Returns a new channel that pipes the output of this channel into the * specified channel and preserves this channel's failures without providing * them to the other channel for observation. * * **Example** (Piping while preserving failures) * * ```ts import.meta.vitest * import { Channel, Data, Effect, Exit } from "effect" * * class SourceError extends Data.TaggedError("SourceError")<{ * readonly code: number * }> {} * * // Create a failing source channel * const error = new SourceError({ code: 404 }) * const failingSource = Channel.fail(error) * const safeTransform = Channel.identity() * * // Pipe while preserving source failures * const safePipedChannel = Channel.pipeToOrFail(failingSource, safeTransform) * * Effect.runSync(Effect.exit(Channel.runCollect(safePipedChannel))) // => Exit.fail(error) * ``` * * @stability stable * @category sequencing * @since 2.0.0 */ (self: Channel, that: Channel): Channel; }; /** * Constructs a `Channel` from a scoped effect that will result in a * `Channel` if successful. * * **Example** (Unwrapping channel effects) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class UnwrapError extends Data.TaggedError("UnwrapError")<{ * readonly reason: string * }> {} * * // Create an effect that produces a channel * const channelEffect = Effect.succeed( * Channel.fromIterable([1, 2, 3]) * ) * * // Unwrap the effect to get the channel * const unwrappedChannel = Channel.unwrap(channelEffect) * * Effect.runSync(Channel.runCollect(unwrappedChannel)) // => [1, 2, 3] * ``` * * @stability stable * @category constructors * @since 2.0.0 */ export declare const unwrap: (channel: Effect.Effect, E, R>) => Channel | R2>; /** * Runs a channel with a scope provided for the duration of the channel * execution, removing the channel's `Scope` requirement. * * @stability stable * @category resource management * @since 2.0.0 */ export declare const scoped: (self: Channel) => Channel>; /** * Runs an input handler against the upstream pull while the wrapped channel * runs without receiving upstream input directly. * * **Details** * * 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.meta.vitest * import { Channel, Effect } from "effect" * * // Create a base channel * const baseChannel = Channel.fromIterable([1, 2, 3]) * * // Drain the embedded input while the base channel runs * const embeddedChannel = Channel.embedInput( * baseChannel, * (upstream) => * upstream.pipe( * Effect.forever, * Effect.ignore * ) * ) * await Effect.runPromise(Channel.runCollect(embeddedChannel)) // => [1, 2, 3] * ``` * * @stability stable * @category sequencing * @since 2.0.0 */ export declare const embedInput: { /** * Runs an input handler against the upstream pull while the wrapped channel * runs without receiving upstream input directly. * * **Details** * * 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.meta.vitest * import { Channel, Effect } from "effect" * * // Create a base channel * const baseChannel = Channel.fromIterable([1, 2, 3]) * * // Drain the embedded input while the base channel runs * const embeddedChannel = Channel.embedInput( * baseChannel, * (upstream) => * upstream.pipe( * Effect.forever, * Effect.ignore * ) * ) * await Effect.runPromise(Channel.runCollect(embeddedChannel)) // => [1, 2, 3] * ``` * * @stability stable * @category sequencing * @since 2.0.0 */ (input: (upstream: Pull.Pull) => Effect.Effect): (self: Channel) => Channel; /** * Runs an input handler against the upstream pull while the wrapped channel * runs without receiving upstream input directly. * * **Details** * * 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.meta.vitest * import { Channel, Effect } from "effect" * * // Create a base channel * const baseChannel = Channel.fromIterable([1, 2, 3]) * * // Drain the embedded input while the base channel runs * const embeddedChannel = Channel.embedInput( * baseChannel, * (upstream) => * upstream.pipe( * Effect.forever, * Effect.ignore * ) * ) * await Effect.runPromise(Channel.runCollect(embeddedChannel)) // => [1, 2, 3] * ``` * * @stability stable * @category sequencing * @since 2.0.0 */ (self: Channel, input: (upstream: Pull.Pull) => Effect.Effect): Channel; }; /** * 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 * * @stability stable * @category buffering * @since 2.0.0 */ export declare const buffer: { /** * 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 * * @stability stable * @category buffering * @since 2.0.0 */ (options: { readonly capacity: "unbounded"; } | { readonly capacity: number; readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; }): (self: Channel) => Channel; /** * 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 * * @stability stable * @category buffering * @since 2.0.0 */ (self: Channel, options: { readonly capacity: "unbounded"; } | { readonly capacity: number; readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; }): Channel; }; /** * 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 * * @stability stable * @category buffering * @since 4.0.0 */ export declare const bufferArray: { /** * 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 * * @stability stable * @category buffering * @since 4.0.0 */ (options: { readonly capacity: "unbounded"; } | { readonly capacity: number; readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; }): (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>) => Channel, OutErr, OutDone, InElem, InErr, InDone, Env>; /** * 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 * * @stability stable * @category buffering * @since 4.0.0 */ (self: Channel, OutErr, OutDone, InElem, InErr, InDone, Env>, options: { readonly capacity: "unbounded"; } | { readonly capacity: number; readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; }): Channel, OutErr, OutDone, InElem, InErr, InDone, Env>; }; /** * 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. * * @stability stable * @category interruption * @since 2.0.0 */ export declare const interruptWhen: { /** * 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. * * @stability stable * @category interruption * @since 2.0.0 */ (effect: Effect.Effect): (self: Channel) => Channel; /** * 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. * * @stability stable * @category interruption * @since 2.0.0 */ (self: Channel, effect: Effect.Effect): Channel; }; /** * Stops a channel when the specified effect completes or fails. * * **Details** * * If the effect completes before the channel is done, its success value becomes * the returned channel's done value. If the effect fails, the returned channel * fails with that error. If the channel completes first, the channel's done * value is preserved. * * @stability stable * @category interruption * @since 4.0.0 */ export declare const haltWhen: { /** * Stops a channel when the specified effect completes or fails. * * **Details** * * If the effect completes before the channel is done, its success value becomes * the returned channel's done value. If the effect fails, the returned channel * fails with that error. If the channel completes first, the channel's done * value is preserved. * * @stability stable * @category interruption * @since 4.0.0 */ (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. * * @stability stable * @category interruption * @since 4.0.0 */ (self: Channel, effect: Effect.Effect): Channel; }; /** * Attaches a finalizer that runs only when the channel exits with failure. * * **Details** * * The finalizer receives the failure `Cause`. The original channel failure is * preserved. The finalizer itself must not fail. * * @stability stable * @category error handling * @since 4.0.0 */ export declare const onError: { /** * Attaches a finalizer that runs only when the channel exits with failure. * * **Details** * * The finalizer receives the failure `Cause`. The original channel failure is * preserved. The finalizer itself must not fail. * * @stability stable * @category error handling * @since 4.0.0 */ (finalizer: (cause: Cause.Cause) => Effect.Effect): (self: Channel) => Channel; /** * Attaches a finalizer that runs only when the channel exits with failure. * * **Details** * * The finalizer receives the failure `Cause`. The original channel failure is * preserved. The finalizer itself must not fail. * * @stability stable * @category error handling * @since 4.0.0 */ (self: Channel, finalizer: (cause: Cause.Cause) => Effect.Effect): Channel; }; /** * 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) * * ```ts import.meta.vitest * import { Channel, Data, Effect, Exit } from "effect" * * class ExitError extends Data.TaggedError("ExitError")<{ * readonly stage: string * }> {} * * // Create a channel * const dataChannel = Channel.fromIterable([1, 2, 3]) * * // Attach exit handler * const exits: Array> = [] * const channelWithExit = Channel.onExit(dataChannel, (exit) => { * exits.push(exit) * return Effect.void * }) * const observed = [await Effect.runPromise(Channel.runCollect(channelWithExit)), exits] // => [[1, 2, 3], [Exit.void]] * ``` * * @stability stable * @category resource management * @since 4.0.0 */ export declare const onExit: { /** * 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) * * ```ts import.meta.vitest * import { Channel, Data, Effect, Exit } from "effect" * * class ExitError extends Data.TaggedError("ExitError")<{ * readonly stage: string * }> {} * * // Create a channel * const dataChannel = Channel.fromIterable([1, 2, 3]) * * // Attach exit handler * const exits: Array> = [] * const channelWithExit = Channel.onExit(dataChannel, (exit) => { * exits.push(exit) * return Effect.void * }) * const observed = [await Effect.runPromise(Channel.runCollect(channelWithExit)), exits] // => [[1, 2, 3], [Exit.void]] * ``` * * @stability stable * @category resource management * @since 4.0.0 */ (finalizer: (e: Exit.Exit) => Effect.Effect): (self: Channel) => Channel; /** * 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) * * ```ts import.meta.vitest * import { Channel, Data, Effect, Exit } from "effect" * * class ExitError extends Data.TaggedError("ExitError")<{ * readonly stage: string * }> {} * * // Create a channel * const dataChannel = Channel.fromIterable([1, 2, 3]) * * // Attach exit handler * const exits: Array> = [] * const channelWithExit = Channel.onExit(dataChannel, (exit) => { * exits.push(exit) * return Effect.void * }) * const observed = [await Effect.runPromise(Channel.runCollect(channelWithExit)), exits] // => [[1, 2, 3], [Exit.void]] * ``` * * @stability stable * @category resource management * @since 4.0.0 */ (self: Channel, finalizer: (e: Exit.Exit) => Effect.Effect): Channel; }; /** * Runs an effect before the channel starts. * * **Details** * * The effect's successful value is ignored. If the effect fails, the returned * channel fails before running the source channel. * * @stability stable * @category hooks * @since 4.0.0 */ export declare const onStart: { /** * Runs an effect before the channel starts. * * **Details** * * The effect's successful value is ignored. If the effect fails, the returned * channel fails before running the source channel. * * @stability stable * @category hooks * @since 4.0.0 */ (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. * * @stability stable * @category hooks * @since 4.0.0 */ (self: Channel, onStart: Effect.Effect): Channel; }; /** * Runs an effect the first time the channel emits an output element. * * **When to use** * * Use when initialization depends on the first output element rather than only * on channel startup. * * **Details** * * The effect receives the first emitted element. The first element is still * emitted unchanged. The effect is not run if the channel completes without * emitting an element. * * @stability stable * @category hooks * @since 4.0.0 */ export declare const onFirst: { /** * Runs an effect the first time the channel emits an output element. * * **When to use** * * Use when initialization depends on the first output element rather than only * on channel startup. * * **Details** * * The effect receives the first emitted element. The first element is still * emitted unchanged. The effect is not run if the channel completes without * emitting an element. * * @stability stable * @category hooks * @since 4.0.0 */ (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. * * @stability stable * @category hooks * @since 4.0.0 */ (self: Channel, onFirst: (element: Types.NoInfer) => Effect.Effect): Channel; }; /** * Runs an effect when the channel completes successfully. * * **Details** * * The effect runs before the original done value is propagated. The effect is * not run when the channel fails. If the effect fails, the returned channel * fails with that error. * * @stability stable * @category hooks * @since 4.0.0 */ export declare const onEnd: { /** * Runs an effect when the channel completes successfully. * * **Details** * * The effect runs before the original done value is propagated. The effect is * not run when the channel fails. If the effect fails, the returned channel * fails with that error. * * @stability stable * @category hooks * @since 4.0.0 */ (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. * * @stability stable * @category hooks * @since 4.0.0 */ (self: Channel, onEnd: Effect.Effect): Channel; }; /** * 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) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class EnsureError extends Data.TaggedError("EnsureError")<{ * readonly operation: string * }> {} * * // Create a channel * const dataChannel = Channel.fromIterable([1, 2, 3]) * * // Ensure cleanup always runs * const events: Array = [] * const channelWithCleanup = Channel.ensuring( * dataChannel, * Effect.sync(() => events.push("cleanup")) * ) * const observed = [await Effect.runPromise(Channel.runCollect(channelWithCleanup)), events] // => [[1, 2, 3], ["cleanup"]] * ``` * * @stability stable * @category resource management * @since 2.0.0 */ export declare const ensuring: { /** * 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) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class EnsureError extends Data.TaggedError("EnsureError")<{ * readonly operation: string * }> {} * * // Create a channel * const dataChannel = Channel.fromIterable([1, 2, 3]) * * // Ensure cleanup always runs * const events: Array = [] * const channelWithCleanup = Channel.ensuring( * dataChannel, * Effect.sync(() => events.push("cleanup")) * ) * const observed = [await Effect.runPromise(Channel.runCollect(channelWithCleanup)), events] // => [[1, 2, 3], ["cleanup"]] * ``` * * @stability stable * @category resource management * @since 2.0.0 */ (finalizer: Effect.Effect): (self: Channel) => Channel; /** * 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) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class EnsureError extends Data.TaggedError("EnsureError")<{ * readonly operation: string * }> {} * * // Create a channel * const dataChannel = Channel.fromIterable([1, 2, 3]) * * // Ensure cleanup always runs * const events: Array = [] * const channelWithCleanup = Channel.ensuring( * dataChannel, * Effect.sync(() => events.push("cleanup")) * ) * const observed = [await Effect.runPromise(Channel.runCollect(channelWithCleanup)), events] // => [[1, 2, 3], ["cleanup"]] * ``` * * @stability stable * @category resource management * @since 2.0.0 */ (self: Channel, finalizer: Effect.Effect): Channel; }; /** * Creates a channel from the specified services. * * @stability stable * @category accessors * @since 2.0.0 */ export declare const contextWith: (f: (context: Context.Context) => Channel) => Channel; /** * Provides a `Context` to the channel, removing the corresponding service * requirements from the returned channel. * * @stability stable * @category providing services * @since 2.0.0 */ export declare const provideContext: { /** * Provides a `Context` to the channel, removing the corresponding service * requirements from the returned channel. * * @stability stable * @category providing services * @since 2.0.0 */ (context: Context.Context): (self: Channel) => Channel>; /** * Provides a `Context` to the channel, removing the corresponding service * requirements from the returned channel. * * @stability stable * @category providing services * @since 2.0.0 */ (self: Channel, context: Context.Context): Channel>; }; /** * Provides a concrete service for a context key, removing that service * requirement from the returned channel. * * @stability stable * @category providing services * @since 2.0.0 */ export declare const provideService: { /** * Provides a concrete service for a context key, removing that service * requirement from the returned channel. * * @stability stable * @category providing services * @since 2.0.0 */ (key: Context.Key, service: NoInfer): (self: Channel) => Channel>; /** * Provides a concrete service for a context key, removing that service * requirement from the returned channel. * * @stability stable * @category providing services * @since 2.0.0 */ (self: Channel, key: Context.Key, service: NoInfer): Channel>; }; /** * Provides a service to the channel after obtaining it from an effect. * * **When to use** * * Use to supply a channel dependency when constructing the service itself is * effectful or can fail. * * **Details** * * If the service effect fails, the returned channel fails. The provided service * removes the corresponding service requirement from the returned channel. * * @stability stable * @category providing services * @since 4.0.0 */ export declare const provideServiceEffect: { /** * Provides a service to the channel after obtaining it from an effect. * * **When to use** * * Use to supply a channel dependency when constructing the service itself is * effectful or can fail. * * **Details** * * If the service effect fails, the returned channel fails. The provided service * removes the corresponding service requirement from the returned channel. * * @stability stable * @category providing services * @since 4.0.0 */ (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. * * @stability stable * @category providing services * @since 4.0.0 */ (self: Channel, key: Context.Key, service: Effect.Effect, ES, RS>): Channel | RS>; }; /** * Provides a `Layer` or `Context` to the channel, removing the corresponding * service requirements. * * **Details** * * Providing a `Context` delegates to `provideContext`. Providing a `Layer` * builds the layer in the channel scope. Use `options.local` to build a fresh * layer instance for this provision. * * @stability stable * @category providing services * @since 4.0.0 */ export declare const provide: { /** * Provides a `Layer` or `Context` to the channel, removing the corresponding * service requirements. * * **Details** * * Providing a `Context` delegates to `provideContext`. Providing a `Layer` * builds the layer in the channel scope. Use `options.local` to build a fresh * layer instance for this provision. * * @stability stable * @category providing services * @since 4.0.0 */ (layer: Layer.Layer | Context.Context, options?: { readonly local?: boolean | undefined; } | undefined): (self: Channel) => Channel | R>; /** * Provides a `Layer` or `Context` to the channel, removing the corresponding * service requirements. * * **Details** * * Providing a `Context` delegates to `provideContext`. Providing a `Layer` * builds the layer in the channel scope. Use `options.local` to build a fresh * layer instance for this provision. * * @stability stable * @category providing services * @since 4.0.0 */ (self: Channel, layer: Layer.Layer | Context.Context, options?: { readonly local?: boolean | undefined; } | undefined): Channel | R>; }; /** * 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. * * @stability stable * @category providing services * @since 4.0.0 */ export declare const updateContext: { /** * 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. * * @stability stable * @category providing services * @since 4.0.0 */ (f: (context: Context.Context) => Context.Context): (self: Channel) => Channel; /** * 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. * * @stability stable * @category providing services * @since 4.0.0 */ (self: Channel, f: (context: Context.Context) => Context.Context): Channel; }; /** * Updates a service in the current context before running the channel. * * **Details** * * The existing service is read from the context. The updated service is * provided to the channel under the same key. * * @stability stable * @category providing services * @since 2.0.0 */ export declare const updateService: { /** * Updates a service in the current context before running the channel. * * **Details** * * The existing service is read from the context. The updated service is * provided to the channel under the same key. * * @stability stable * @category providing services * @since 2.0.0 */ (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. * * @stability stable * @category providing services * @since 2.0.0 */ (self: Channel, service: Context.Key, f: (service: NoInfer) => S): Channel; }; /** * 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. * * @stability stable * @category tracing * @since 2.0.0 */ export declare const withSpan: { /** * 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. * * @stability stable * @category tracing * @since 2.0.0 */ (name: string, options?: SpanOptions): (self: Channel) => Channel>; /** * 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. * * @stability stable * @category tracing * @since 2.0.0 */ (self: Channel, name: string, options?: SpanOptions): Channel>; }; /** * The starting channel for Do notation, emitting an empty object. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Do: Channel<{}>; declare const let_: { (name: Exclude, f: (a: NoInfer) => B): (self: Channel) => Channel<{ [K in N | keyof OutElem]: K extends keyof OutElem ? OutElem[K] : B; }, OutErr, OutDone, InElem, InErr, InDone, R>; (self: Channel, name: Exclude, f: (a: NoInfer) => B): Channel<{ [K in N | keyof OutElem]: K extends keyof OutElem ? OutElem[K] : B; }, OutErr, OutDone, InElem, InErr, InDone, R>; }; export { /** * Adds a computed field to each object emitted by a channel. * * @stability stable * @category mapping * @since 4.0.0 */ 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. * * @stability stable * @category sequencing * @since 4.0.0 */ export declare const bind: { /** * Adds a field to each object emitted by a channel by running another channel * derived from that object. * * **Details** * * The field name must not already exist on the emitted object. The derived * channel's output becomes the value of the new field. `options.concurrency` * and `options.bufferSize` control how derived channels are flattened. * * @stability stable * @category sequencing * @since 4.0.0 */ (name: Exclude, f: (a: NoInfer) => Channel, options?: { readonly concurrency?: Types.Concurrency | undefined; readonly bufferSize?: number | undefined; }): (self: Channel) => Channel<{ [K in N | keyof OutElem]: K extends keyof OutElem ? OutElem[K] : B; }, OutErr2 | OutErr, OutDone, InElem & InElem2, InErr & InErr2, InDone & InDone2, Env2 | Env>; /** * Adds a field to each object emitted by a channel by running another channel * derived from that object. * * **Details** * * The field name must not already exist on the emitted object. The derived * channel's output becomes the value of the new field. `options.concurrency` * and `options.bufferSize` control how derived channels are flattened. * * @stability stable * @category sequencing * @since 4.0.0 */ (self: Channel, name: Exclude, f: (a: NoInfer) => Channel, options?: { readonly concurrency?: Types.Concurrency | undefined; readonly bufferSize?: number | undefined; }): Channel<{ [K in N | keyof OutElem]: K extends keyof OutElem ? OutElem[K] : B; }, OutErr2 | OutErr, OutDone, InElem & InElem2, InErr & InErr2, InDone & InDone2, Env2 | Env>; }; /** * Wraps each output element in an object under the specified field name. * * **When to use** * * Use when you need to start a Channel Do-notation chain from an existing * output value by assigning that value to a field name. * * @see {@link Do} for starting Do notation from an empty object * @see {@link bind} for adding a field produced by another channel * @see {@link let_ let} for adding a computed field * * @stability stable * @category mapping * @since 4.0.0 */ export declare const bindTo: { /** * Wraps each output element in an object under the specified field name. * * **When to use** * * Use when you need to start a Channel Do-notation chain from an existing * output value by assigning that value to a field name. * * @see {@link Do} for starting Do notation from an empty object * @see {@link bind} for adding a field produced by another channel * @see {@link let_ let} for adding a computed field * * @stability stable * @category mapping * @since 4.0.0 */ (name: N): (self: Channel) => Channel<{ [K in N]: OutElem; }, OutErr, OutDone, InElem, InErr, InDone, Env>; /** * Wraps each output element in an object under the specified field name. * * **When to use** * * Use when you need to start a Channel Do-notation chain from an existing * output value by assigning that value to a field name. * * @see {@link Do} for starting Do notation from an empty object * @see {@link bind} for adding a field produced by another channel * @see {@link let_ let} for adding a computed field * * @stability stable * @category mapping * @since 4.0.0 */ (self: Channel, name: N): Channel<{ [K in N]: OutElem; }, OutErr, OutDone, InElem, InErr, InDone, Env>; }; /** * Runs a channel and counts the number of elements it outputs. * * **Example** (Counting channel output) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class CountError extends Data.TaggedError("CountError")<{ * readonly reason: string * }> {} * * // Create a channel with multiple elements * const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5]) * * // Count the elements * const countEffect = Channel.runCount(numbersChannel) * * Effect.runSync(countEffect) // => 5 * ``` * * @stability stable * @category running * @since 4.0.0 */ export declare const runCount: (self: Channel) => Effect.Effect; /** * Runs a channel and discards all output elements, returning only the final result. * * **Example** (Draining channel output at runtime) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class DrainError extends Data.TaggedError("DrainError")<{ * readonly stage: string * }> {} * * // Create a channel that outputs elements and completes with a result * const resultChannel = Channel.fromIterable([1, 2, 3]) * const completedChannel = Channel.concat(resultChannel, Channel.end("completed")) * * // Drain all elements and get only the final result * const drainEffect = Channel.runDrain(completedChannel) * * Effect.runSync(drainEffect) // => "completed" * ``` * * @stability stable * @category running * @since 2.0.0 */ export declare const runDrain: (self: Channel) => Effect.Effect; /** * Runs a channel and applies an effect to each output element. * * **Example** (Running effects for each output) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class ForEachError extends Data.TaggedError("ForEachError")<{ * readonly element: unknown * }> {} * * // Create a channel with numbers * const numbersChannel = Channel.fromIterable([1, 2, 3]) * * // Run forEach to process each element * const processed: Array = [] * const forEachEffect = Channel.runForEach( * numbersChannel, * (n) => Effect.sync(() => processed.push(n)) * ) * * await Effect.runPromise(forEachEffect) * processed // => [1, 2, 3] * ``` * * @stability stable * @category running * @since 4.0.0 */ export declare const runForEach: { /** * Runs a channel and applies an effect to each output element. * * **Example** (Running effects for each output) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class ForEachError extends Data.TaggedError("ForEachError")<{ * readonly element: unknown * }> {} * * // Create a channel with numbers * const numbersChannel = Channel.fromIterable([1, 2, 3]) * * // Run forEach to process each element * const processed: Array = [] * const forEachEffect = Channel.runForEach( * numbersChannel, * (n) => Effect.sync(() => processed.push(n)) * ) * * await Effect.runPromise(forEachEffect) * processed // => [1, 2, 3] * ``` * * @stability stable * @category running * @since 4.0.0 */ (f: (o: OutElem) => Effect.Effect): (self: Channel) => Effect.Effect; /** * Runs a channel and applies an effect to each output element. * * **Example** (Running effects for each output) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class ForEachError extends Data.TaggedError("ForEachError")<{ * readonly element: unknown * }> {} * * // Create a channel with numbers * const numbersChannel = Channel.fromIterable([1, 2, 3]) * * // Run forEach to process each element * const processed: Array = [] * const forEachEffect = Channel.runForEach( * numbersChannel, * (n) => Effect.sync(() => processed.push(n)) * ) * * await Effect.runPromise(forEachEffect) * processed // => [1, 2, 3] * ``` * * @stability stable * @category running * @since 4.0.0 */ (self: Channel, f: (o: OutElem) => Effect.Effect): Effect.Effect; }; /** * 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`. * * @stability stable * @category running * @since 4.0.0 */ export declare const runForEachWhile: { /** * 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`. * * @stability stable * @category running * @since 4.0.0 */ (f: (o: OutElem) => Effect.Effect): (self: Channel) => Effect.Effect; /** * 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`. * * @stability stable * @category running * @since 4.0.0 */ (self: Channel, f: (o: OutElem) => Effect.Effect): Effect.Effect; }; /** * Concatenates a channel's `Uint8Array` chunks into a single `Uint8Array`. * * **Gotchas** * * This materializes the full content in memory. The source channel must not * reuse or mutate emitted buffers, which are retained until collection completes. * * **Example** (Joining channel byte chunks) * * ```ts import.meta.vitest * import { Channel, Effect } from "effect" * * const channel = Channel.fromArray([ * [new Uint8Array([1, 2])], * [new Uint8Array([3, 4])] * ] as const) * * const bytes = Effect.runSync(Channel.mkUint8Array(channel)) * Array.from(bytes) // => [1, 2, 3, 4] * ``` * * @stability stable * @category running * @since 4.0.0 */ export declare const mkUint8Array: (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>) => Effect.Effect, OutErr, Env>; /** * Runs a channel and collects all output elements into an array. * * **Example** (Collecting channel output) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class CollectError extends Data.TaggedError("CollectError")<{ * readonly reason: string * }> {} * * // Create a channel with elements * const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5]) * * // Collect all elements into an array * const collectEffect = Channel.runCollect(numbersChannel) * * Effect.runSync(collectEffect) // => [1, 2, 3, 4, 5] * ``` * * @stability stable * @category running * @since 2.0.0 */ export declare const runCollect: (self: Channel) => Effect.Effect, OutErr, Env>; /** * 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. * * @stability stable * @category running * @since 4.0.0 */ export declare const runHead: (self: Channel) => Effect.Effect, OutErr, Env>; /** * 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. * * @stability stable * @category running * @since 4.0.0 */ export declare const runLast: (self: Channel) => Effect.Effect, OutErr, Env>; /** * Runs a channel and folds over all output elements with an accumulator. * * **Example** (Folding channel output) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class FoldError extends Data.TaggedError("FoldError")<{ * readonly operation: string * }> {} * * // Create a channel with numbers * const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5]) * * // Fold to calculate sum * const sumEffect = Channel.runFold(numbersChannel, () => 0, (acc, n) => acc + n) * * Effect.runSync(sumEffect) // => 15 * ``` * * @stability stable * @category running * @since 4.0.0 */ export declare const runFold: { /** * Runs a channel and folds over all output elements with an accumulator. * * **Example** (Folding channel output) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class FoldError extends Data.TaggedError("FoldError")<{ * readonly operation: string * }> {} * * // Create a channel with numbers * const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5]) * * // Fold to calculate sum * const sumEffect = Channel.runFold(numbersChannel, () => 0, (acc, n) => acc + n) * * Effect.runSync(sumEffect) // => 15 * ``` * * @stability stable * @category running * @since 4.0.0 */ (initial: LazyArg, f: (acc: Z, o: OutElem) => Z): (self: Channel) => Effect.Effect; /** * Runs a channel and folds over all output elements with an accumulator. * * **Example** (Folding channel output) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class FoldError extends Data.TaggedError("FoldError")<{ * readonly operation: string * }> {} * * // Create a channel with numbers * const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5]) * * // Fold to calculate sum * const sumEffect = Channel.runFold(numbersChannel, () => 0, (acc, n) => acc + n) * * Effect.runSync(sumEffect) // => 15 * ``` * * @stability stable * @category running * @since 4.0.0 */ (self: Channel, initial: LazyArg, f: (acc: Z, o: OutElem) => Z): Effect.Effect; }; /** * 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. * * @stability stable * @category running * @since 4.0.0 */ export declare const runFoldEffect: { /** * 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. * * @stability stable * @category running * @since 4.0.0 */ (initial: LazyArg, f: (acc: Z, o: OutElem) => Effect.Effect): (self: Channel) => Effect.Effect; /** * 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. * * @stability stable * @category running * @since 4.0.0 */ (self: Channel, initial: LazyArg, f: (acc: Z, o: OutElem) => Effect.Effect): Effect.Effect; }; /** * 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) * * ```ts import.meta.vitest * import { Channel, Data, Effect } from "effect" * * class PullError extends Data.TaggedError("PullError")<{ * readonly step: string * }> {} * * // Create a channel * const numbersChannel = Channel.fromIterable([1, 2, 3]) * * const program = Effect.scoped(Effect.gen(function*() { * const pull = yield* Channel.toPull(numbersChannel) * return [yield* pull, yield* pull, yield* pull] * })) * await Effect.runPromise(program) // => [1, 2, 3] * ``` * * @stability stable * @category destructors * @since 2.0.0 */ export declare const toPull: (self: Channel) => Effect.Effect, never, Env | Scope.Scope>; /** * Converts a channel to a Pull within an existing scope. * * **Example** (Converting channels to scoped pulls) * * ```ts import.meta.vitest * import { Channel, Data, Effect, Scope } from "effect" * * class ScopedPullError extends Data.TaggedError("ScopedPullError")<{ * readonly reason: string * }> {} * * // Create a channel * const numbersChannel = Channel.fromIterable([1, 2, 3]) * * // Convert to Pull with explicit scope * const scopedPullEffect = Effect.gen(function*() { * const scope = yield* Effect.scope * const pull = yield* Channel.toPullScoped(numbersChannel, scope) * return [yield* pull, yield* pull, yield* pull] * }) * await Effect.runPromise(Effect.scoped(scopedPullEffect)) // => [1, 2, 3] * ``` * * @stability stable * @category destructors * @since 4.0.0 */ export declare const toPullScoped: (self: Channel, scope: Scope.Scope) => Effect.Effect, never, Env>; /** * Runs a channel and offers each output element into a queue. * * **Details** * * When the channel completes, the queue is ended. When the channel fails, the * queue is failed with the channel's cause. The returned effect itself * completes with `void`. * * @stability stable * @category destructors * @since 4.0.0 */ export declare const runIntoQueue: { /** * Runs a channel and offers each output element into a queue. * * **Details** * * When the channel completes, the queue is ended. When the channel fails, the * queue is failed with the channel's cause. The returned effect itself * completes with `void`. * * @stability stable * @category destructors * @since 4.0.0 */ (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`. * * @stability stable * @category destructors * @since 4.0.0 */ (self: Channel, queue: Queue.Queue): Effect.Effect; }; /** * Runs a channel that emits non-empty arrays and offers each array element into * a queue. * * **Details** * * When the channel completes, the queue is ended. When the channel fails, the * queue is failed with the channel's cause. The returned effect itself * completes with `void`. * * @stability stable * @category destructors * @since 4.0.0 */ export declare const runIntoQueueArray: { /** * Runs a channel that emits non-empty arrays and offers each array element into * a queue. * * **Details** * * When the channel completes, the queue is ended. When the channel fails, the * queue is failed with the channel's cause. The returned effect itself * completes with `void`. * * @stability stable * @category destructors * @since 4.0.0 */ (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`. * * @stability stable * @category destructors * @since 4.0.0 */ (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>, queue: Queue.Queue): Effect.Effect; }; /** * 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) * * ```ts import.meta.vitest * import { Channel, Data, Effect, Queue } from "effect" * * class QueueError extends Data.TaggedError("QueueError")<{ * readonly operation: string * }> {} * * // Create a channel with data * const dataChannel = Channel.fromIterable([1, 2, 3, 4, 5]) * * // Convert to queue for concurrent processing * const program = Effect.scoped(Effect.gen(function*() { * const queue = yield* Channel.toQueue(dataChannel, { capacity: 32 }) * return yield* Queue.takeBetween(queue, 5, 5) * })) * await Effect.runPromise(program) // => [1, 2, 3, 4, 5] * ``` * * @stability stable * @category destructors * @since 2.0.0 */ export declare const toQueue: { /** * 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) * * ```ts import.meta.vitest * import { Channel, Data, Effect, Queue } from "effect" * * class QueueError extends Data.TaggedError("QueueError")<{ * readonly operation: string * }> {} * * // Create a channel with data * const dataChannel = Channel.fromIterable([1, 2, 3, 4, 5]) * * // Convert to queue for concurrent processing * const program = Effect.scoped(Effect.gen(function*() { * const queue = yield* Channel.toQueue(dataChannel, { capacity: 32 }) * return yield* Queue.takeBetween(queue, 5, 5) * })) * await Effect.runPromise(program) // => [1, 2, 3, 4, 5] * ``` * * @stability stable * @category destructors * @since 2.0.0 */ (options: { readonly capacity: "unbounded"; } | { readonly capacity: number; readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; }): (self: Channel) => Effect.Effect, never, Env | Scope.Scope>; /** * 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) * * ```ts import.meta.vitest * import { Channel, Data, Effect, Queue } from "effect" * * class QueueError extends Data.TaggedError("QueueError")<{ * readonly operation: string * }> {} * * // Create a channel with data * const dataChannel = Channel.fromIterable([1, 2, 3, 4, 5]) * * // Convert to queue for concurrent processing * const program = Effect.scoped(Effect.gen(function*() { * const queue = yield* Channel.toQueue(dataChannel, { capacity: 32 }) * return yield* Queue.takeBetween(queue, 5, 5) * })) * await Effect.runPromise(program) // => [1, 2, 3, 4, 5] * ``` * * @stability stable * @category destructors * @since 2.0.0 */ (self: Channel, options: { readonly capacity: "unbounded"; } | { readonly capacity: number; readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; }): 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. * * @stability stable * @category destructors * @since 4.0.0 */ export declare const toQueueArray: { /** * Creates a scoped queue and forks an array-emitting channel to feed it. * * **Details** * * Each element inside emitted non-empty arrays is offered to the queue. Channel * completion and failure are signaled through the queue. The queue is shut down * when the surrounding scope closes. * * @stability stable * @category destructors * @since 4.0.0 */ (options: { readonly capacity: "unbounded"; } | { readonly capacity: number; readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; }): (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>) => Effect.Effect, never, Env | Scope.Scope>; /** * Creates a scoped queue and forks an array-emitting channel to feed it. * * **Details** * * Each element inside emitted non-empty arrays is offered to the queue. Channel * completion and failure are signaled through the queue. The queue is shut down * when the surrounding scope closes. * * @stability stable * @category destructors * @since 4.0.0 */ (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>, options: { readonly capacity: "unbounded"; } | { readonly capacity: number; readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; }): Effect.Effect, never, Env | Scope.Scope>; }; /** * 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`. * * @stability stable * @category destructors * @since 2.0.0 */ export declare const toPubSub: { /** * Converts a channel to a PubSub for concurrent consumption. * * **Details** * * `shutdownOnEnd` indicates whether the PubSub should be shut down when the * channel ends. By default this is `true`. * * @stability stable * @category destructors * @since 2.0.0 */ (options: { readonly capacity: "unbounded"; readonly replay?: number | undefined; readonly shutdownOnEnd?: boolean | undefined; } | { readonly capacity: number; readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; readonly replay?: number | undefined; readonly shutdownOnEnd?: boolean | undefined; }): (self: Channel) => Effect.Effect, never, Env | Scope.Scope>; /** * 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`. * * @stability stable * @category destructors * @since 2.0.0 */ (self: Channel, options: { readonly capacity: "unbounded"; readonly replay?: number | undefined; readonly shutdownOnEnd?: boolean | undefined; } | { readonly capacity: number; readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; readonly replay?: number | undefined; readonly shutdownOnEnd?: boolean | undefined; }): Effect.Effect, never, Env | Scope.Scope>; }; /** * Runs a channel and publishes each output element to a `PubSub`. * * **Details** * * The channel's output values are published as individual PubSub messages. Use * `options.shutdownOnEnd` to shut down the PubSub when channel execution ends. * * @stability stable * @category destructors * @since 4.0.0 */ export declare const runIntoPubSub: { /** * Runs a channel and publishes each output element to a `PubSub`. * * **Details** * * The channel's output values are published as individual PubSub messages. Use * `options.shutdownOnEnd` to shut down the PubSub when channel execution ends. * * @stability stable * @category destructors * @since 4.0.0 */ (pubsub: PubSub.PubSub, options?: { readonly shutdownOnEnd?: boolean | undefined; } | undefined): (self: Channel) => Effect.Effect; /** * Runs a channel and publishes each output element to a `PubSub`. * * **Details** * * The channel's output values are published as individual PubSub messages. Use * `options.shutdownOnEnd` to shut down the PubSub when channel execution ends. * * @stability stable * @category destructors * @since 4.0.0 */ (self: Channel, pubsub: PubSub.PubSub, options?: { readonly shutdownOnEnd?: boolean | undefined; } | undefined): Effect.Effect; }; /** * Converts an array-emitting channel to a scoped `PubSub` for concurrent * consumption. * * **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`. * * @stability stable * @category destructors * @since 4.0.0 */ export declare const toPubSubArray: { /** * Converts an array-emitting channel to a scoped `PubSub` for concurrent * consumption. * * **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`. * * @stability stable * @category destructors * @since 4.0.0 */ (options: { readonly capacity: "unbounded"; readonly replay?: number | undefined; readonly shutdownOnEnd?: boolean | undefined; } | { readonly capacity: number; readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; readonly replay?: number | undefined; readonly shutdownOnEnd?: boolean | undefined; }): (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>) => Effect.Effect, never, Env | Scope.Scope>; /** * Converts an array-emitting channel to a scoped `PubSub` for concurrent * consumption. * * **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`. * * @stability stable * @category destructors * @since 4.0.0 */ (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>, options: { readonly capacity: "unbounded"; readonly replay?: number | undefined; readonly shutdownOnEnd?: boolean | undefined; } | { readonly capacity: number; readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; readonly replay?: number | undefined; readonly shutdownOnEnd?: boolean | undefined; }): Effect.Effect, never, Env | Scope.Scope>; }; /** * Runs an array-emitting channel and publishes each array element to a * `PubSub`. * * **Details** * * Each element inside emitted non-empty arrays is published as an individual * PubSub message. Use `options.shutdownOnEnd` to shut down the PubSub when * channel execution ends. * * @stability stable * @category destructors * @since 4.0.0 */ export declare const runIntoPubSubArray: { /** * Runs an array-emitting channel and publishes each array element to a * `PubSub`. * * **Details** * * Each element inside emitted non-empty arrays is published as an individual * PubSub message. Use `options.shutdownOnEnd` to shut down the PubSub when * channel execution ends. * * @stability stable * @category destructors * @since 4.0.0 */ (pubsub: PubSub.PubSub, options?: { readonly shutdownOnEnd?: boolean | undefined; } | undefined): (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>) => Effect.Effect; /** * Runs an array-emitting channel and publishes each array element to a * `PubSub`. * * **Details** * * Each element inside emitted non-empty arrays is published as an individual * PubSub message. Use `options.shutdownOnEnd` to shut down the PubSub when * channel execution ends. * * @stability stable * @category destructors * @since 4.0.0 */ (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>, pubsub: PubSub.PubSub, options?: { readonly shutdownOnEnd?: boolean | undefined; } | undefined): Effect.Effect; }; /** * 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, the `PubSub` is ended with its final `Exit`, so every * subscriber, including one that subscribes later, observes completion or * failure once it has consumed its buffered values. * * @stability stable * @category destructors * @since 4.0.0 */ export declare const toPubSubTake: { /** * 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, the `PubSub` is ended with its final `Exit`, so every * subscriber, including one that subscribes later, observes completion or * failure once it has consumed its buffered values. * * @stability stable * @category destructors * @since 4.0.0 */ (options: { readonly capacity: "unbounded"; readonly replay?: number | undefined; } | { readonly capacity: number; readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; readonly replay?: number | undefined; }): (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>) => Effect.Effect>, never, Env | Scope.Scope>; /** * 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, the `PubSub` is ended with its final `Exit`, so every * subscriber, including one that subscribes later, observes completion or * failure once it has consumed its buffered values. * * @stability stable * @category destructors * @since 4.0.0 */ (self: Channel, OutErr, OutDone, unknown, unknown, unknown, Env>, options: { readonly capacity: "unbounded"; readonly replay?: number | undefined; } | { readonly capacity: number; readonly strategy?: "dropping" | "sliding" | "suspend" | undefined; readonly replay?: number | undefined; }): Effect.Effect>, never, Env | Scope.Scope>; }; //# sourceMappingURL=Channel.d.ts.map