/** * @since 2.0.0 */ import type * as Cause from "./Cause.js" import type * as Channel from "./Channel.js" import type * as Chunk from "./Chunk.js" import type * as Context from "./Context.js" import type * as Duration from "./Duration.js" import type * as Effect from "./Effect.js" import type * as Either from "./Either.js" import type * as Exit from "./Exit.js" import type { LazyArg } from "./Function.js" import type * as HashMap from "./HashMap.js" import type * as HashSet from "./HashSet.js" import * as internal from "./internal/sink.js" import type * as MergeDecision from "./MergeDecision.js" import type * as Option from "./Option.js" import type { Pipeable } from "./Pipeable.js" import type { Predicate, Refinement } from "./Predicate.js" import type * as PubSub from "./PubSub.js" import type * as Queue from "./Queue.js" import type * as Scope from "./Scope.js" import type * as Types from "./Types.js" import type * as Unify from "./Unify.js" /** * @since 2.0.0 * @category symbols */ export const SinkTypeId: unique symbol = internal.SinkTypeId /** * @since 2.0.0 * @category symbols */ export type SinkTypeId = typeof SinkTypeId /** * A `Sink` is used to consume elements produced by a `Stream`. * You can think of a sink as a function that will consume a variable amount of * `In` elements (could be 0, 1, or many), might fail with an error of type `E`, * and will eventually yield a value of type `A` together with a remainder of * type `L` (i.e. any leftovers). * * @since 2.0.0 * @category models */ export interface Sink extends Sink.Variance, Pipeable {} /** * @since 2.0.0 * @category models */ export interface SinkUnify extends Effect.EffectUnify { Sink?: () => A[Unify.typeSymbol] extends | Sink< infer A, infer In, infer L, infer E, infer R > | infer _ ? Sink : never } /** * @category models * @since 2.0.0 */ export interface SinkUnifyIgnore extends Effect.EffectUnifyIgnore { Sink?: true } /** * @since 2.0.0 * @category models */ declare module "./Effect.js" { interface Effect extends Sink {} interface EffectUnifyIgnore { Sink?: true } } /** * @since 2.0.0 */ export declare namespace Sink { /** * @since 2.0.0 * @category models */ export interface Variance { readonly [SinkTypeId]: VarianceStruct } /** * @since 2.0.0 * @category models */ export interface VarianceStruct { _A: Types.Covariant _In: Types.Contravariant _L: Types.Covariant _E: Types.Covariant _R: Types.Covariant } } /** * Replaces this sink's result with the provided value. * * @since 2.0.0 * @category mapping */ export const as: { /** * Replaces this sink's result with the provided value. * * @since 2.0.0 * @category mapping */ (a: A2): (self: Sink) => Sink /** * Replaces this sink's result with the provided value. * * @since 2.0.0 * @category mapping */ (self: Sink, a: A2): Sink } = internal.as /** * A sink that collects all elements into a `Chunk`. * * @since 2.0.0 * @category constructors */ export const collectAll: () => Sink, In> = internal.collectAll /** * A sink that collects first `n` elements into a chunk. * * @since 2.0.0 * @category constructors */ export const collectAllN: (n: number) => Sink, In, In> = internal.collectAllN /** * Repeatedly runs the sink and accumulates its results into a `Chunk`. * * @since 2.0.0 * @category utils */ export const collectAllFrom: ( self: Sink ) => Sink, In, L, E, R> = internal.collectAllFrom /** * A sink that collects all of its inputs into a map. The keys are extracted * from inputs using the keying function `key`; if multiple inputs use the * same key, they are merged using the `merge` function. * * @since 2.0.0 * @category constructors */ export const collectAllToMap: ( key: (input: In) => K, merge: (x: In, y: In) => In ) => Sink, In> = internal.collectAllToMap /** * A sink that collects first `n` keys into a map. The keys are calculated * from inputs using the keying function `key`; if multiple inputs use the the * same key, they are merged using the `merge` function. * * @since 2.0.0 * @category constructors */ export const collectAllToMapN: ( n: number, key: (input: In) => K, merge: (x: In, y: In) => In ) => Sink, In, In> = internal.collectAllToMapN /** * A sink that collects all of its inputs into a set. * * @since 2.0.0 * @category constructors */ export const collectAllToSet: () => Sink, In> = internal.collectAllToSet /** * A sink that collects first `n` distinct inputs into a set. * * @since 2.0.0 * @category constructors */ export const collectAllToSetN: (n: number) => Sink, In, In> = internal.collectAllToSetN /** * Accumulates incoming elements into a chunk until predicate `p` is * satisfied. * * @since 2.0.0 * @category constructors */ export const collectAllUntil: (p: Predicate) => Sink, In, In> = internal.collectAllUntil /** * Accumulates incoming elements into a chunk until effectful predicate `p` is * satisfied. * * @since 2.0.0 * @category constructors */ export const collectAllUntilEffect: ( p: (input: In) => Effect.Effect ) => Sink, In, In, E, R> = internal.collectAllUntilEffect /** * Accumulates incoming elements into a chunk as long as they verify predicate * `p`. * * @since 2.0.0 * @category constructors */ export const collectAllWhile: { /** * Accumulates incoming elements into a chunk as long as they verify predicate * `p`. * * @since 2.0.0 * @category constructors */ (refinement: Refinement): Sink, In, In> /** * Accumulates incoming elements into a chunk as long as they verify predicate * `p`. * * @since 2.0.0 * @category constructors */ (predicate: Predicate): Sink, In, In> } = internal.collectAllWhile /** * Accumulates incoming elements into a chunk as long as they verify effectful * predicate `p`. * * @since 2.0.0 * @category constructors */ export const collectAllWhileEffect: ( predicate: (input: In) => Effect.Effect ) => Sink, In, In, E, R> = internal.collectAllWhileEffect /** * Repeatedly runs the sink for as long as its results satisfy the predicate * `p`. The sink's results will be accumulated using the stepping function `f`. * * @since 2.0.0 * @category utils */ export const collectAllWhileWith: { /** * Repeatedly runs the sink for as long as its results satisfy the predicate * `p`. The sink's results will be accumulated using the stepping function `f`. * * @since 2.0.0 * @category utils */ ( options: { readonly initial: S; readonly while: Predicate; readonly body: (s: S, a: A) => S } ): (self: Sink) => Sink /** * Repeatedly runs the sink for as long as its results satisfy the predicate * `p`. The sink's results will be accumulated using the stepping function `f`. * * @since 2.0.0 * @category utils */ ( self: Sink, options: { readonly initial: S; readonly while: Predicate; readonly body: (s: S, a: A) => S } ): Sink } = internal.collectAllWhileWith as any /** * Collects the leftovers from the stream when the sink succeeds and returns * them as part of the sink's result. * * @since 2.0.0 * @category utils */ export const collectLeftover: ( self: Sink ) => Sink<[A, Chunk.Chunk], In, never, E, R> = internal.collectLeftover /** * Transforms this sink's input elements. * * @since 2.0.0 * @category mapping */ export const mapInput: { /** * Transforms this sink's input elements. * * @since 2.0.0 * @category mapping */ (f: (input: In0) => In): (self: Sink) => Sink /** * Transforms this sink's input elements. * * @since 2.0.0 * @category mapping */ (self: Sink, f: (input: In0) => In): Sink } = internal.mapInput /** * Effectfully transforms this sink's input elements. * * @since 2.0.0 * @category mapping */ export const mapInputEffect: { /** * Effectfully transforms this sink's input elements. * * @since 2.0.0 * @category mapping */ (f: (input: In0) => Effect.Effect): (self: Sink) => Sink /** * Effectfully transforms this sink's input elements. * * @since 2.0.0 * @category mapping */ (self: Sink, f: (input: In0) => Effect.Effect): Sink } = internal.mapInputEffect /** * Transforms this sink's input chunks. `f` must preserve chunking-invariance. * * @since 2.0.0 * @category mapping */ export const mapInputChunks: { /** * Transforms this sink's input chunks. `f` must preserve chunking-invariance. * * @since 2.0.0 * @category mapping */ (f: (chunk: Chunk.Chunk) => Chunk.Chunk): (self: Sink) => Sink /** * Transforms this sink's input chunks. `f` must preserve chunking-invariance. * * @since 2.0.0 * @category mapping */ ( self: Sink, f: (chunk: Chunk.Chunk) => Chunk.Chunk ): Sink } = internal.mapInputChunks /** * Effectfully transforms this sink's input chunks. `f` must preserve * chunking-invariance. * * @since 2.0.0 * @category mapping */ export const mapInputChunksEffect: { /** * Effectfully transforms this sink's input chunks. `f` must preserve * chunking-invariance. * * @since 2.0.0 * @category mapping */ (f: (chunk: Chunk.Chunk) => Effect.Effect, E2, R2>): (self: Sink) => Sink /** * Effectfully transforms this sink's input chunks. `f` must preserve * chunking-invariance. * * @since 2.0.0 * @category mapping */ ( self: Sink, f: (chunk: Chunk.Chunk) => Effect.Effect, E2, R2> ): Sink } = internal.mapInputChunksEffect /** * A sink that counts the number of elements fed to it. * * @since 2.0.0 * @category constructors */ export const count: Sink = internal.count /** * Creates a sink halting with the specified defect. * * @since 2.0.0 * @category constructors */ export const die: (defect: unknown) => Sink = internal.die /** * Creates a sink halting with the specified message, wrapped in a * `RuntimeException`. * * @since 2.0.0 * @category constructors */ export const dieMessage: (message: string) => Sink = internal.dieMessage /** * Creates a sink halting with the specified defect. * * @since 2.0.0 * @category constructors */ export const dieSync: (evaluate: LazyArg) => Sink = internal.dieSync /** * Transforms both inputs and result of this sink using the provided * functions. * * @since 2.0.0 * @category mapping */ export const dimap: { /** * Transforms both inputs and result of this sink using the provided * functions. * * @since 2.0.0 * @category mapping */ ( options: { readonly onInput: (input: In0) => In; readonly onDone: (a: A) => A2 } ): (self: Sink) => Sink /** * Transforms both inputs and result of this sink using the provided * functions. * * @since 2.0.0 * @category mapping */ ( self: Sink, options: { readonly onInput: (input: In0) => In; readonly onDone: (a: A) => A2 } ): Sink } = internal.dimap /** * Effectfully transforms both inputs and result of this sink using the * provided functions. * * @since 2.0.0 * @category mapping */ export const dimapEffect: { /** * Effectfully transforms both inputs and result of this sink using the * provided functions. * * @since 2.0.0 * @category mapping */ ( options: { readonly onInput: (input: In0) => Effect.Effect readonly onDone: (a: A) => Effect.Effect } ): (self: Sink) => Sink /** * Effectfully transforms both inputs and result of this sink using the * provided functions. * * @since 2.0.0 * @category mapping */ ( self: Sink, options: { readonly onInput: (input: In0) => Effect.Effect readonly onDone: (a: A) => Effect.Effect } ): Sink } = internal.dimapEffect /** * Transforms both input chunks and result of this sink using the provided * functions. * * @since 2.0.0 * @category mapping */ export const dimapChunks: { /** * Transforms both input chunks and result of this sink using the provided * functions. * * @since 2.0.0 * @category mapping */ ( options: { readonly onInput: (chunk: Chunk.Chunk) => Chunk.Chunk; readonly onDone: (a: A) => A2 } ): (self: Sink) => Sink /** * Transforms both input chunks and result of this sink using the provided * functions. * * @since 2.0.0 * @category mapping */ ( self: Sink, options: { readonly onInput: (chunk: Chunk.Chunk) => Chunk.Chunk; readonly onDone: (a: A) => A2 } ): Sink } = internal.dimapChunks /** * Effectfully transforms both input chunks and result of this sink using the * provided functions. `f` and `g` must preserve chunking-invariance. * * @since 2.0.0 * @category mapping */ export const dimapChunksEffect: { /** * Effectfully transforms both input chunks and result of this sink using the * provided functions. `f` and `g` must preserve chunking-invariance. * * @since 2.0.0 * @category mapping */ ( options: { readonly onInput: (chunk: Chunk.Chunk) => Effect.Effect, E2, R2> readonly onDone: (a: A) => Effect.Effect } ): (self: Sink) => Sink /** * Effectfully transforms both input chunks and result of this sink using the * provided functions. `f` and `g` must preserve chunking-invariance. * * @since 2.0.0 * @category mapping */ ( self: Sink, options: { readonly onInput: (chunk: Chunk.Chunk) => Effect.Effect, E2, R2> readonly onDone: (a: A) => Effect.Effect } ): Sink } = internal.dimapChunksEffect /** * A sink that ignores its inputs. * * @since 2.0.0 * @category constructors */ export const drain: Sink = internal.drain /** * Creates a sink that drops `n` elements. * * @since 2.0.0 * @category constructors */ export const drop: (n: number) => Sink = internal.drop /** * Drops incoming elements until the predicate is satisfied. * * @since 2.0.0 * @category constructors */ export const dropUntil: (predicate: Predicate) => Sink = internal.dropUntil /** * Drops incoming elements until the effectful predicate is satisfied. * * @since 2.0.0 * @category constructors */ export const dropUntilEffect: ( predicate: (input: In) => Effect.Effect ) => Sink = internal.dropUntilEffect /** * Drops incoming elements as long as the predicate is satisfied. * * @since 2.0.0 * @category constructors */ export const dropWhile: (predicate: Predicate) => Sink = internal.dropWhile /** * Drops incoming elements as long as the effectful predicate is satisfied. * * @since 2.0.0 * @category constructors */ export const dropWhileEffect: ( predicate: (input: In) => Effect.Effect ) => Sink = internal.dropWhileEffect /** * Returns a new sink with an attached finalizer. The finalizer is guaranteed * to be executed so long as the sink begins execution (and regardless of * whether or not it completes). * * @since 2.0.0 * @category finalization */ export const ensuring: { /** * Returns a new sink with an attached finalizer. The finalizer is guaranteed * to be executed so long as the sink begins execution (and regardless of * whether or not it completes). * * @since 2.0.0 * @category finalization */ (finalizer: Effect.Effect): (self: Sink) => Sink /** * Returns a new sink with an attached finalizer. The finalizer is guaranteed * to be executed so long as the sink begins execution (and regardless of * whether or not it completes). * * @since 2.0.0 * @category finalization */ (self: Sink, finalizer: Effect.Effect): Sink } = internal.ensuring /** * Returns a new sink with an attached finalizer. The finalizer is guaranteed * to be executed so long as the sink begins execution (and regardless of * whether or not it completes). * * @since 2.0.0 * @category finalization */ export const ensuringWith: { /** * Returns a new sink with an attached finalizer. The finalizer is guaranteed * to be executed so long as the sink begins execution (and regardless of * whether or not it completes). * * @since 2.0.0 * @category finalization */ (finalizer: (exit: Exit.Exit) => Effect.Effect): (self: Sink) => Sink /** * Returns a new sink with an attached finalizer. The finalizer is guaranteed * to be executed so long as the sink begins execution (and regardless of * whether or not it completes). * * @since 2.0.0 * @category finalization */ ( self: Sink, finalizer: (exit: Exit.Exit) => Effect.Effect ): Sink } = internal.ensuringWith /** * Accesses the whole context of the sink. * * @since 2.0.0 * @category constructors */ export const context: () => Sink, unknown, never, never, R> = internal.context /** * Accesses the context of the sink. * * @since 2.0.0 * @category constructors */ export const contextWith: (f: (context: Context.Context) => Z) => Sink = internal.contextWith /** * Accesses the context of the sink in the context of an effect. * * @since 2.0.0 * @category constructors */ export const contextWithEffect: ( f: (context: Context.Context) => Effect.Effect ) => Sink = internal.contextWithEffect /** * Accesses the context of the sink in the context of a sink. * * @since 2.0.0 * @category constructors */ export const contextWithSink: ( f: (context: Context.Context) => Sink ) => Sink = internal.contextWithSink /** * A sink that returns whether all elements satisfy the specified predicate. * * @since 2.0.0 * @category constructors */ export const every: (predicate: Predicate) => Sink = internal.every /** * A sink that always fails with the specified error. * * @since 2.0.0 * @category constructors */ export const fail: (e: E) => Sink = internal.fail /** * A sink that always fails with the specified lazily evaluated error. * * @since 2.0.0 * @category constructors */ export const failSync: (evaluate: LazyArg) => Sink = internal.failSync /** * Creates a sink halting with a specified `Cause`. * * @since 2.0.0 * @category constructors */ export const failCause: (cause: Cause.Cause) => Sink = internal.failCause /** * Creates a sink halting with a specified lazily evaluated `Cause`. * * @since 2.0.0 * @category constructors */ export const failCauseSync: (evaluate: LazyArg>) => Sink = internal.failCauseSync /** * Filters the sink's input with the given predicate. * * @since 2.0.0 * @category filtering */ export const filterInput: { /** * Filters the sink's input with the given predicate. * * @since 2.0.0 * @category filtering */ (f: Refinement): (self: Sink) => Sink /** * Filters the sink's input with the given predicate. * * @since 2.0.0 * @category filtering */ (f: Predicate): (self: Sink) => Sink } = internal.filterInput /** * Effectfully filter the input of this sink using the specified predicate. * * @since 2.0.0 * @category filtering */ export const filterInputEffect: { /** * Effectfully filter the input of this sink using the specified predicate. * * @since 2.0.0 * @category filtering */ (f: (input: In1) => Effect.Effect): (self: Sink) => Sink /** * Effectfully filter the input of this sink using the specified predicate. * * @since 2.0.0 * @category filtering */ ( self: Sink, f: (input: In1) => Effect.Effect ): Sink } = internal.filterInputEffect /** * Creates a sink that produces values until one verifies the predicate `f`. * * @since 2.0.0 * @category elements */ export const findEffect: { /** * Creates a sink that produces values until one verifies the predicate `f`. * * @since 2.0.0 * @category elements */ (f: (a: A) => Effect.Effect): (self: Sink) => Sink, In, L, E2 | E, R2 | R> /** * Creates a sink that produces values until one verifies the predicate `f`. * * @since 2.0.0 * @category elements */ (self: Sink, f: (a: A) => Effect.Effect): Sink, In, L, E | E2, R | R2> } = internal.findEffect as any /** * A sink that folds its inputs with the provided function, termination * predicate and initial state. * * @since 2.0.0 * @category folding */ export const fold: (s: S, contFn: Predicate, f: (s: S, input: In) => S) => Sink = internal.fold /** * Folds over the result of the sink * * @since 2.0.0 * @category folding */ export const foldSink: { /** * Folds over the result of the sink * * @since 2.0.0 * @category folding */ ( options: { readonly onFailure: (err: E) => Sink readonly onSuccess: (a: A) => Sink } ): (self: Sink) => Sink /** * Folds over the result of the sink * * @since 2.0.0 * @category folding */ ( self: Sink, options: { readonly onFailure: (err: E) => Sink readonly onSuccess: (a: A) => Sink } ): Sink } = internal.foldSink /** * A sink that folds its input chunks with the provided function, termination * predicate and initial state. `contFn` condition is checked only for the * initial value and at the end of processing of each chunk. `f` and `contFn` * must preserve chunking-invariance. * * @since 2.0.0 * @category constructors */ export const foldChunks: ( s: S, contFn: Predicate, f: (s: S, chunk: Chunk.Chunk) => S ) => Sink = internal.foldChunks /** * A sink that effectfully folds its input chunks with the provided function, * termination predicate and initial state. `contFn` condition is checked only * for the initial value and at the end of processing of each chunk. `f` and * `contFn` must preserve chunking-invariance. * * @since 2.0.0 * @category constructors */ export const foldChunksEffect: ( s: S, contFn: Predicate, f: (s: S, chunk: Chunk.Chunk) => Effect.Effect ) => Sink = internal.foldChunksEffect /** * A sink that effectfully folds its inputs with the provided function, * termination predicate and initial state. * * @since 2.0.0 * @category constructors */ export const foldEffect: ( s: S, contFn: Predicate, f: (s: S, input: In) => Effect.Effect ) => Sink = internal.foldEffect /** * A sink that folds its inputs with the provided function and initial state. * * @since 2.0.0 * @category constructors */ export const foldLeft: (s: S, f: (s: S, input: In) => S) => Sink = internal.foldLeft /** * A sink that folds its input chunks with the provided function and initial * state. `f` must preserve chunking-invariance. * * @since 2.0.0 * @category constructors */ export const foldLeftChunks: (s: S, f: (s: S, chunk: Chunk.Chunk) => S) => Sink = internal.foldLeftChunks /** * A sink that effectfully folds its input chunks with the provided function * and initial state. `f` must preserve chunking-invariance. * * @since 2.0.0 * @category constructors */ export const foldLeftChunksEffect: ( s: S, f: (s: S, chunk: Chunk.Chunk) => Effect.Effect ) => Sink = internal.foldLeftChunksEffect /** * A sink that effectfully folds its inputs with the provided function and * initial state. * * @since 2.0.0 * @category constructors */ export const foldLeftEffect: ( s: S, f: (s: S, input: In) => Effect.Effect ) => Sink = internal.foldLeftEffect /** * Creates a sink that folds elements of type `In` into a structure of type * `S` until `max` elements have been folded. * * Like `Sink.foldWeighted`, but with a constant cost function of `1`. * * @since 2.0.0 * @category constructors */ export const foldUntil: (s: S, max: number, f: (s: S, input: In) => S) => Sink = internal.foldUntil /** * Creates a sink that effectfully folds elements of type `In` into a * structure of type `S` until `max` elements have been folded. * * Like `Sink.foldWeightedEffect` but with a constant cost function of `1`. * * @since 2.0.0 * @category constructors */ export const foldUntilEffect: ( s: S, max: number, f: (s: S, input: In) => Effect.Effect ) => Sink = internal.foldUntilEffect /** * Creates a sink that folds elements of type `In` into a structure of type `S`, * until `max` worth of elements (determined by the `costFn`) have been folded. * * **Note** * * Elements that have an individual cost larger than `max` will force the sink * to cross the `max` cost. See `Sink.foldWeightedDecompose` for a variant * that can handle these cases. * * @since 2.0.0 * @category constructors */ export const foldWeighted: ( options: { readonly initial: S readonly maxCost: number readonly cost: (s: S, input: In) => number readonly body: (s: S, input: In) => S } ) => Sink = internal.foldWeighted /** * Creates a sink that folds elements of type `In` into a structure of type * `S`, until `max` worth of elements (determined by the `costFn`) have been * folded. * * The `decompose` function will be used for decomposing elements that cause * an `S` aggregate to cross `max` into smaller elements. For example: * * ```ts skip-type-checking * pipe( * Stream.make(1, 5, 1), * Stream.transduce( * Sink.foldWeightedDecompose( * Chunk.empty(), * 4, * (n: number) => n, * (n: number) => Chunk.make(n - 1, 1), * (acc, el) => pipe(acc, Chunk.append(el)) * ) * ), * Stream.runCollect * ) * ``` * * The stream would emit the elements `Chunk(1), Chunk(4), Chunk(1, 1)`. * * Be vigilant with this function, it has to generate "simpler" values or the * fold may never end. A value is considered indivisible if `decompose` yields * the empty chunk or a single-valued chunk. In these cases, there is no other * choice than to yield a value that will cross the threshold. * * `Sink.foldWeightedDecomposeEffect` allows the decompose function to return an * effect value, and consequently it allows the sink to fail. * * @since 2.0.0 * @category constructors */ export const foldWeightedDecompose: ( options: { readonly initial: S readonly maxCost: number readonly cost: (s: S, input: In) => number readonly decompose: (input: In) => Chunk.Chunk readonly body: (s: S, input: In) => S } ) => Sink = internal.foldWeightedDecompose /** * Creates a sink that effectfully folds elements of type `In` into a * structure of type `S`, until `max` worth of elements (determined by the * `costFn`) have been folded. * * The `decompose` function will be used for decomposing elements that cause * an `S` aggregate to cross `max` into smaller elements. Be vigilant with * this function, it has to generate "simpler" values or the fold may never * end. A value is considered indivisible if `decompose` yields the empty * chunk or a single-valued chunk. In these cases, there is no other choice * than to yield a value that will cross the threshold. * * See `Sink.foldWeightedDecompose` for an example. * * @since 2.0.0 * @category constructors */ export const foldWeightedDecomposeEffect: ( options: { readonly initial: S readonly maxCost: number readonly cost: (s: S, input: In) => Effect.Effect readonly decompose: (input: In) => Effect.Effect, E2, R2> readonly body: (s: S, input: In) => Effect.Effect } ) => Sink = internal.foldWeightedDecomposeEffect /** * Creates a sink that effectfully folds elements of type `In` into a * structure of type `S`, until `max` worth of elements (determined by the * `costFn`) have been folded. * * @note * Elements that have an individual cost larger than `max` will force the * sink to cross the `max` cost. See `Sink.foldWeightedDecomposeEffect` for * a variant that can handle these cases. * * @since 2.0.0 * @category constructors */ export const foldWeightedEffect: ( options: { readonly initial: S readonly maxCost: number readonly cost: (s: S, input: In) => Effect.Effect readonly body: (s: S, input: In) => Effect.Effect } ) => Sink = internal.foldWeightedEffect /** * A sink that executes the provided effectful function for every element fed * to it. * * @since 2.0.0 * @category constructors */ export const forEach: (f: (input: In) => Effect.Effect) => Sink = internal.forEach /** * A sink that executes the provided effectful function for every chunk fed to * it. * * @since 2.0.0 * @category constructors */ export const forEachChunk: ( f: (input: Chunk.Chunk) => Effect.Effect ) => Sink = internal.forEachChunk /** * A sink that executes the provided effectful function for every chunk fed to * it until `f` evaluates to `false`. * * @since 2.0.0 * @category constructors */ export const forEachChunkWhile: ( f: (input: Chunk.Chunk) => Effect.Effect ) => Sink = internal.forEachChunkWhile /** * A sink that executes the provided effectful function for every element fed * to it until `f` evaluates to `false`. * * @since 2.0.0 * @category constructors */ export const forEachWhile: (f: (input: In) => Effect.Effect) => Sink = internal.forEachWhile /** * Runs this sink until it yields a result, then uses that result to create * another sink from the provided function which will continue to run until it * yields a result. * * This function essentially runs sinks in sequence. * * @since 2.0.0 * @category sequencing */ export const flatMap: { /** * Runs this sink until it yields a result, then uses that result to create * another sink from the provided function which will continue to run until it * yields a result. * * This function essentially runs sinks in sequence. * * @since 2.0.0 * @category sequencing */ (f: (a: A) => Sink): (self: Sink) => Sink /** * Runs this sink until it yields a result, then uses that result to create * another sink from the provided function which will continue to run until it * yields a result. * * This function essentially runs sinks in sequence. * * @since 2.0.0 * @category sequencing */ (self: Sink, f: (a: A) => Sink): Sink } = internal.flatMap /** * Creates a sink from a `Channel`. * * @since 2.0.0 * @category constructors */ export const fromChannel: ( channel: Channel.Channel, Chunk.Chunk, E, never, A, unknown, R> ) => Sink = internal.fromChannel /** * Creates a `Channel` from a Sink. * * @since 2.0.0 * @category constructors */ export const toChannel: ( self: Sink ) => Channel.Channel, Chunk.Chunk, E, never, A, unknown, R> = internal.toChannel /** * Creates a single-value sink produced from an effect. * * @since 2.0.0 * @category constructors */ export const fromEffect: (effect: Effect.Effect) => Sink = internal.fromEffect /** * Create a sink which publishes each element to the specified `PubSub`. * * If the `shutdown` parameter is `true`, the `PubSub` will be shutdown after * the sink is evaluated (defaults to `false`). * * @since 2.0.0 * @category constructors */ export const fromPubSub: ( pubsub: PubSub.PubSub, options?: { readonly shutdown?: boolean | undefined } ) => Sink = internal.fromPubSub /** * Creates a sink from a chunk processing function. * * @since 2.0.0 * @category constructors */ export const fromPush: ( push: Effect.Effect< (_: Option.Option>) => Effect.Effect, Chunk.Chunk], R>, never, R > ) => Sink> = internal.fromPush /** * Create a sink which enqueues each element into the specified queue. * * If the `shutdown` parameter is `true`, the queue will be shutdown after the * sink is evaluated (defaults to `false`). * * @since 2.0.0 * @category constructors */ export const fromQueue: ( queue: Queue.Enqueue, options?: { readonly shutdown?: boolean | undefined } ) => Sink = internal.fromQueue /** * Creates a sink containing the first value. * * @since 2.0.0 * @category constructors */ export const head: () => Sink, In, In> = internal.head /** * Drains the remaining elements from the stream after the sink finishes * * @since 2.0.0 * @category utils */ export const ignoreLeftover: (self: Sink) => Sink = internal.ignoreLeftover /** * Creates a sink containing the last value. * * @since 2.0.0 * @category constructors */ export const last: () => Sink, In, In> = internal.last /** * Creates a sink that does not consume any input but provides the given chunk * as its leftovers * * @since 2.0.0 * @category constructors */ export const leftover: (chunk: Chunk.Chunk) => Sink = internal.leftover /** * Transforms this sink's result. * * @since 2.0.0 * @category mapping */ export const map: { /** * Transforms this sink's result. * * @since 2.0.0 * @category mapping */ (f: (a: A) => A2): (self: Sink) => Sink /** * Transforms this sink's result. * * @since 2.0.0 * @category mapping */ (self: Sink, f: (a: A) => A2): Sink } = internal.map /** * Effectfully transforms this sink's result. * * @since 2.0.0 * @category mapping */ export const mapEffect: { /** * Effectfully transforms this sink's result. * * @since 2.0.0 * @category mapping */ (f: (a: A) => Effect.Effect): (self: Sink) => Sink /** * Effectfully transforms this sink's result. * * @since 2.0.0 * @category mapping */ (self: Sink, f: (a: A) => Effect.Effect): Sink } = internal.mapEffect /** * Transforms the errors emitted by this sink using `f`. * * @since 2.0.0 * @category mapping */ export const mapError: { /** * Transforms the errors emitted by this sink using `f`. * * @since 2.0.0 * @category mapping */ (f: (error: E) => E2): (self: Sink) => Sink /** * Transforms the errors emitted by this sink using `f`. * * @since 2.0.0 * @category mapping */ (self: Sink, f: (error: E) => E2): Sink } = internal.mapError /** * Transforms the leftovers emitted by this sink using `f`. * * @since 2.0.0 * @category mapping */ export const mapLeftover: { /** * Transforms the leftovers emitted by this sink using `f`. * * @since 2.0.0 * @category mapping */ (f: (leftover: L) => L2): (self: Sink) => Sink /** * Transforms the leftovers emitted by this sink using `f`. * * @since 2.0.0 * @category mapping */ (self: Sink, f: (leftover: L) => L2): Sink } = internal.mapLeftover /** * Creates a sink which transforms it's inputs into a string. * * @since 2.0.0 * @category constructors */ export const mkString: Sink = internal.mkString /** * Creates a sink which never terminates. * * @since 2.0.0 * @category constructors */ export const never: Sink = internal.never /** * Switch to another sink in case of failure * * @since 2.0.0 * @category error handling */ export const orElse: { /** * Switch to another sink in case of failure * * @since 2.0.0 * @category error handling */ (that: LazyArg>): (self: Sink) => Sink /** * Switch to another sink in case of failure * * @since 2.0.0 * @category error handling */ (self: Sink, that: LazyArg>): Sink } = internal.orElse /** * Provides the sink with its required context, which eliminates its * dependency on `R`. * * @since 2.0.0 * @category context */ export const provideContext: { /** * Provides the sink with its required context, which eliminates its * dependency on `R`. * * @since 2.0.0 * @category context */ (context: Context.Context): (self: Sink) => Sink /** * Provides the sink with its required context, which eliminates its * dependency on `R`. * * @since 2.0.0 * @category context */ (self: Sink, context: Context.Context): Sink } = internal.provideContext /** * Runs both sinks in parallel on the input, , returning the result or the * error from the one that finishes first. * * @since 2.0.0 * @category utils */ export const race: { /** * Runs both sinks in parallel on the input, , returning the result or the * error from the one that finishes first. * * @since 2.0.0 * @category utils */ (that: Sink): (self: Sink) => Sink /** * Runs both sinks in parallel on the input, , returning the result or the * error from the one that finishes first. * * @since 2.0.0 * @category utils */ (self: Sink, that: Sink): Sink } = internal.race /** * Runs both sinks in parallel on the input, returning the result or the error * from the one that finishes first. * * @since 2.0.0 * @category utils */ export const raceBoth: { /** * Runs both sinks in parallel on the input, returning the result or the error * from the one that finishes first. * * @since 2.0.0 * @category utils */ ( that: Sink, options?: { readonly capacity?: number | undefined } | undefined ): (self: Sink) => Sink, In & In1, L1 | L, E1 | E, R1 | R> /** * Runs both sinks in parallel on the input, returning the result or the error * from the one that finishes first. * * @since 2.0.0 * @category utils */ ( self: Sink, that: Sink, options?: { readonly capacity?: number | undefined } | undefined ): Sink, In & In1, L | L1, E | E1, R | R1> } = internal.raceBoth /** * Runs both sinks in parallel on the input, using the specified merge * function as soon as one result or the other has been computed. * * @since 2.0.0 * @category utils */ export const raceWith: { /** * Runs both sinks in parallel on the input, using the specified merge * function as soon as one result or the other has been computed. * * @since 2.0.0 * @category utils */ ( options: { readonly other: Sink readonly onSelfDone: (exit: Exit.Exit) => MergeDecision.MergeDecision readonly onOtherDone: (exit: Exit.Exit) => MergeDecision.MergeDecision readonly capacity?: number | undefined } ): (self: Sink) => Sink /** * Runs both sinks in parallel on the input, using the specified merge * function as soon as one result or the other has been computed. * * @since 2.0.0 * @category utils */ ( self: Sink, options: { readonly other: Sink readonly onSelfDone: (exit: Exit.Exit) => MergeDecision.MergeDecision readonly onOtherDone: (exit: Exit.Exit) => MergeDecision.MergeDecision readonly capacity?: number | undefined } ): Sink } = internal.raceWith /** * @since 2.0.0 * @category error handling */ export const refineOrDie: { /** * @since 2.0.0 * @category error handling */ (pf: (error: E) => Option.Option): (self: Sink) => Sink /** * @since 2.0.0 * @category error handling */ (self: Sink, pf: (error: E) => Option.Option): Sink } = internal.refineOrDie /** * @since 2.0.0 * @category error handling */ export const refineOrDieWith: { /** * @since 2.0.0 * @category error handling */ (pf: (error: E) => Option.Option, f: (error: E) => unknown): (self: Sink) => Sink /** * @since 2.0.0 * @category error handling */ ( self: Sink, pf: (error: E) => Option.Option, f: (error: E) => unknown ): Sink } = internal.refineOrDieWith /** * A sink that returns whether an element satisfies the specified predicate. * * @since 2.0.0 * @category constructors */ export const some: (predicate: Predicate) => Sink = internal.some /** * Splits the sink on the specified predicate, returning a new sink that * consumes elements until an element after the first satisfies the specified * predicate. * * @since 2.0.0 * @category utils */ export const splitWhere: { /** * Splits the sink on the specified predicate, returning a new sink that * consumes elements until an element after the first satisfies the specified * predicate. * * @since 2.0.0 * @category utils */ (f: Predicate): (self: Sink) => Sink /** * Splits the sink on the specified predicate, returning a new sink that * consumes elements until an element after the first satisfies the specified * predicate. * * @since 2.0.0 * @category utils */ (self: Sink, f: Predicate): Sink } = internal.splitWhere /** * A sink that immediately ends with the specified value. * * @since 2.0.0 * @category constructors */ export const succeed: (a: A) => Sink = internal.succeed /** * A sink that sums incoming numeric values. * * @since 2.0.0 * @category constructors */ export const sum: Sink = internal.sum /** * Summarize a sink by running an effect when the sink starts and again when * it completes. * * @since 2.0.0 * @category utils */ export const summarized: { /** * Summarize a sink by running an effect when the sink starts and again when * it completes. * * @since 2.0.0 * @category utils */ (summary: Effect.Effect, f: (start: A2, end: A2) => A3): (self: Sink) => Sink<[A, A3], In, L, E2 | E, R2 | R> /** * Summarize a sink by running an effect when the sink starts and again when * it completes. * * @since 2.0.0 * @category utils */ ( self: Sink, summary: Effect.Effect, f: (start: A2, end: A2) => A3 ): Sink<[A, A3], In, L, E | E2, R | R2> } = internal.summarized /** * Returns a lazily constructed sink that may require effects for its * creation. * * @since 2.0.0 * @category constructors */ export const suspend: (evaluate: LazyArg>) => Sink = internal.suspend /** * A sink that immediately ends with the specified lazy value. * * @since 2.0.0 * @category constructors */ export const sync: (evaluate: LazyArg) => Sink = internal.sync /** * A sink that takes the specified number of values. * * @since 2.0.0 * @category constructors */ export const take: (n: number) => Sink, In, In> = internal.take /** * @since 2.0.0 * @category constructors */ export const timed: Sink = internal.timed /** * Creates a sink produced from an effect. * * @since 2.0.0 * @category constructors */ export const unwrap: ( effect: Effect.Effect, E, R> ) => Sink = internal.unwrap /** * Creates a sink produced from a scoped effect. * * @since 2.0.0 * @category constructors */ export const unwrapScoped: ( effect: Effect.Effect, E, R> ) => Sink> = internal.unwrapScoped /** * Constructs a `Sink` from a function which receives a `Scope` and returns * an effect that will result in a `Sink` if successful. * * @since 3.11.0 * @category constructors */ export const unwrapScopedWith: ( f: (scope: Scope.Scope) => Effect.Effect, E, R> ) => Sink = internal.unwrapScopedWith /** * Returns the sink that executes this one and times its execution. * * @since 2.0.0 * @category utils */ export const withDuration: ( self: Sink ) => Sink<[A, Duration.Duration], In, L, E, R> = internal.withDuration /** * Feeds inputs to this sink until it yields a result, then switches over to * the provided sink until it yields a result, finally combining the two * results into a tuple. * * @since 2.0.0 * @category zipping */ export const zip: { /** * Feeds inputs to this sink until it yields a result, then switches over to * the provided sink until it yields a result, finally combining the two * results into a tuple. * * @since 2.0.0 * @category zipping */ ( that: Sink, options?: { readonly concurrent?: boolean | undefined } | undefined ): (self: Sink) => Sink<[A, A2], In & In2, L2 | L, E2 | E, R2 | R> /** * Feeds inputs to this sink until it yields a result, then switches over to * the provided sink until it yields a result, finally combining the two * results into a tuple. * * @since 2.0.0 * @category zipping */ ( self: Sink, that: Sink, options?: { readonly concurrent?: boolean | undefined } | undefined ): Sink<[A, A2], In & In2, L | L2, E | E2, R | R2> } = internal.zip /** * Like `Sink.zip` but keeps only the result from this sink. * * @since 2.0.0 * @category zipping */ export const zipLeft: { /** * Like `Sink.zip` but keeps only the result from this sink. * * @since 2.0.0 * @category zipping */ ( that: Sink, options?: { readonly concurrent?: boolean | undefined } | undefined ): (self: Sink) => Sink /** * Like `Sink.zip` but keeps only the result from this sink. * * @since 2.0.0 * @category zipping */ ( self: Sink, that: Sink, options?: { readonly concurrent?: boolean | undefined } | undefined ): Sink } = internal.zipLeft /** * Like `Sink.zip` but keeps only the result from `that` sink. * * @since 2.0.0 * @category zipping */ export const zipRight: { /** * Like `Sink.zip` but keeps only the result from `that` sink. * * @since 2.0.0 * @category zipping */ ( that: Sink, options?: { readonly concurrent?: boolean | undefined } | undefined ): (self: Sink) => Sink /** * Like `Sink.zip` but keeps only the result from `that` sink. * * @since 2.0.0 * @category zipping */ ( self: Sink, that: Sink, options?: { readonly concurrent?: boolean | undefined } | undefined ): Sink } = internal.zipRight /** * Feeds inputs to this sink until it yields a result, then switches over to * the provided sink until it yields a result, finally combining the two * results with `f`. * * @since 2.0.0 * @category zipping */ export const zipWith: { /** * Feeds inputs to this sink until it yields a result, then switches over to * the provided sink until it yields a result, finally combining the two * results with `f`. * * @since 2.0.0 * @category zipping */ ( that: Sink, f: (a: A, a2: A2) => A3, options?: { readonly concurrent?: boolean | undefined } | undefined ): (self: Sink) => Sink /** * Feeds inputs to this sink until it yields a result, then switches over to * the provided sink until it yields a result, finally combining the two * results with `f`. * * @since 2.0.0 * @category zipping */ ( self: Sink, that: Sink, f: (a: A, a2: A2) => A3, options?: { readonly concurrent?: boolean | undefined } | undefined ): Sink } = internal.zipWith