From c6d5930a065cb1b1c6e5aa5bd41eda1374012287 Mon Sep 17 00:00:00 2001 From: Giulio Canti Date: Tue, 6 Feb 2024 18:54:05 +0100 Subject: [PATCH] =?UTF-8?q?change=20`Channel`=20type=20parameters=20order?= =?UTF-8?q?=20from=20`Channel` to `Channel` diff --git a/packages/effect/mod.ts b/packages/effect/mod.ts index 79325229d8..36203e774f 100644 --- a/packages/effect/mod.ts +++ b/packages/effect/mod.ts @@ -13,7 +13,8 @@ const enabled = { swapFiberSetParams: false, swapRequestParams: false, swapResourceParams: false, - swapTExitParams: true, + swapTExitParams: false, + swapChannelParams: false, cleanupSTM: false, cleanupEffect: false, cleanupStream: false, @@ -104,6 +105,23 @@ const swapRequestParams = swapParamsEA("Request") const swapResourceParams = swapParamsEA("Resource") const swapTExitParams = swapParamsEA("TExit") +// from: Channel +// +// to: Channel +const swapChannelParams = (ast: cs.ASTPath) => { + const is = filter(ast, "VarianceStruct") + if ( + is(ast.value.typeName) && + ast.value.typeParameters && + ast.value.typeParameters.params.length === 7 + ) { + const params = ast.value.typeParameters.params + const newParams = [params[5], params[2], params[4], params[1], params[6], params[3], params[0]] + popNever(newParams) + ast.value.typeParameters.params = newParams + } +} + const swapSTMParams = swapParamsREA("STM") const swapSTMGenParams = swapParamsREA("STMGen") const swapLayerParams = swapParamsREA("Layer") @@ -169,6 +187,9 @@ export default function transformer(file: cs.FileInfo, api: cs.API) { if (enabled.swapTExitParams) { swapTExitParams(ast) } + if (enabled.swapChannelParams) { + swapChannelParams(ast) + } if (enabled.cleanupEffect) { cleanupEffect(ast) } diff --git a/packages/effect/src/Cause.ts b/packages/effect/src/Cause.ts index 7be69e246b..255675e532 100644 --- a/packages/effect/src/Cause.ts +++ b/packages/effect/src/Cause.ts @@ -193,15 +193,7 @@ export interface YieldableError extends Pipeable, Inspectable, Readonly { readonly [Effect.EffectTypeId]: Effect.Effect.VarianceStruct readonly [Stream.StreamTypeId]: Effect.Effect.VarianceStruct readonly [Sink.SinkTypeId]: Sink.Sink.VarianceStruct - readonly [Channel.ChannelTypeId]: Channel.Channel.VarianceStruct< - never, - unknown, - unknown, - unknown, - this, - never, - never - > + readonly [Channel.ChannelTypeId]: Channel.Channel.VarianceStruct } /** diff --git a/packages/effect/src/Channel.ts b/packages/effect/src/Channel.ts index 16030cdc85..3c8617842f 100644 --- a/packages/effect/src/Channel.ts +++ b/packages/effect/src/Channel.ts @@ -71,8 +71,26 @@ export type ChannelTypeId = typeof ChannelTypeId * @since 2.0.0 * @category models */ -export interface Channel - extends Channel.Variance, Pipeable +// export interface Channel +export interface Channel< + out OutElem, + in InElem = unknown, + out OutErr = never, + in InErr = unknown, + out OutDone = void, + in InDone = unknown, + out Env = never +> extends + Channel.Variance< + OutElem, + InElem, + OutErr, + InErr, + OutDone, + InDone, + Env + >, + Pipeable { [Unify.typeSymbol]?: unknown [Unify.unifySymbol]?: ChannelUnify @@ -86,15 +104,15 @@ export interface Channel extends Effect.EffectUnify { Channel?: () => A[Unify.typeSymbol] extends | Channel< - infer Env, - infer InErr, + infer OutElem, infer InElem, - infer InDone, infer OutErr, - infer OutElem, - infer OutDone + infer InErr, + infer OutDone, + infer InDone, + infer Env > - | infer _ ? Channel + | infer _ ? Channel : never } @@ -111,7 +129,7 @@ export interface ChannelUnifyIgnore extends Effect.EffectUnifyIgnore { * @category models */ declare module "./Effect.js" { - interface Effect extends Channel {} + interface Effect extends Channel {} interface EffectUnifyIgnore { Channel?: true } @@ -125,14 +143,14 @@ export declare namespace Channel { * @since 2.0.0 * @category models */ - export interface Variance { - readonly [ChannelTypeId]: VarianceStruct + export interface Variance { + readonly [ChannelTypeId]: VarianceStruct } /** * @since 2.0.0 * @category models */ - export interface VarianceStruct { + export interface VarianceStruct { _Env: Types.Covariant _InErr: Types.Contravariant _InElem: Types.Contravariant @@ -172,20 +190,25 @@ export interface ChannelException { * @since 2.0.0 * @category constructors */ -export const acquireUseRelease: ( +export const acquireUseRelease: ( acquire: Effect.Effect, - use: (a: Acquired) => Channel, + use: (a: Acquired) => Channel, release: (a: Acquired, exit: Exit.Exit) => Effect.Effect -) => Channel = channel.acquireUseRelease +) => Channel = channel.acquireUseRelease /** * @since 2.0.0 * @category constructors */ -export const acquireReleaseOut: ( - self: Effect.Effect, - release: (z: Z, e: Exit.Exit) => Effect.Effect -) => Channel = core.acquireReleaseOut +export const acquireReleaseOut: { + ( + release: (z: Z, e: Exit.Exit) => Effect.Effect + ): (self: Effect.Effect) => Channel + ( + self: Effect.Effect, + release: (z: Z, e: Exit.Exit) => Effect.Effect + ): Channel +} = core.acquireReleaseOut /** * Returns a new channel that is the same as this one, except the terminal @@ -200,22 +223,22 @@ export const acquireReleaseOut: ( export const as: { ( value: OutDone2 - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, value: OutDone2 - ): Channel + ): Channel } = channel.as /** * @since 2.0.0 * @category mapping */ -export const asUnit: ( - self: Channel -) => Channel = channel.asUnit +export const asUnit: ( + self: Channel +) => Channel = channel.asUnit /** * Creates a channel backed by a buffer. When the buffer is empty, the channel @@ -225,21 +248,17 @@ export const asUnit: ( * @since 2.0.0 * @category constructors */ -export const buffer: ( - options: { - readonly empty: InElem - readonly isEmpty: Predicate - readonly ref: Ref.Ref - } -) => Channel = channel.buffer +export const buffer: ( + options: { readonly empty: InElem; readonly isEmpty: Predicate; readonly ref: Ref.Ref } +) => Channel = channel.buffer /** * @since 2.0.0 * @category constructors */ -export const bufferChunk: ( +export const bufferChunk: ( ref: Ref.Ref> -) => Channel, InDone, InErr, Chunk.Chunk, InDone> = channel.bufferChunk +) => Channel, Chunk.Chunk, InErr, InErr, InDone, InDone> = channel.bufferChunk /** * Returns a new channel that is the same as this one, except if this channel @@ -250,30 +269,30 @@ export const bufferChunk: ( * @category error handling */ export const catchAll: { - ( - f: (error: OutErr) => Channel - ): ( - self: Channel + ( + f: (error: OutErr) => Channel + ): ( + self: Channel ) => Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1, - OutElem1 | OutElem, - OutDone1 | OutDone + InErr & InErr1, + OutDone1 | OutDone, + InDone & InDone1, + Env1 | Env > - ( - self: Channel, - f: (error: OutErr) => Channel + ( + self: Channel, + f: (error: OutErr) => Channel ): Channel< - Env | Env1, - InErr & InErr1, + OutElem | OutElem1, InElem & InElem1, - InDone & InDone1, OutErr1, - OutElem | OutElem1, - OutDone | OutDone1 + InErr & InErr1, + OutDone | OutDone1, + InDone & InDone1, + Env | Env1 > } = channel.catchAll @@ -286,30 +305,30 @@ export const catchAll: { * @category error handling */ export const catchAllCause: { - ( - f: (cause: Cause.Cause) => Channel - ): ( - self: Channel + ( + f: (cause: Cause.Cause) => Channel + ): ( + self: Channel ) => Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1, - OutElem1 | OutElem, - OutDone1 | OutDone + InErr & InErr1, + OutDone1 | OutDone, + InDone & InDone1, + Env1 | Env > - ( - self: Channel, - f: (cause: Cause.Cause) => Channel + ( + self: Channel, + f: (cause: Cause.Cause) => Channel ): Channel< - Env | Env1, - InErr & InErr1, + OutElem | OutElem1, InElem & InElem1, - InDone & InDone1, OutErr1, - OutElem | OutElem1, - OutDone | OutDone1 + InErr & InErr1, + OutDone | OutDone1, + InDone & InDone1, + Env | Env1 > } = core.catchAllCause @@ -319,9 +338,9 @@ export const catchAllCause: { * @since 2.0.0 * @category constructors */ -export const concatAll: ( - channels: Channel, any> -) => Channel = core.concatAll +export const concatAll: ( + channels: Channel, InElem, OutErr, InErr, any, InDone, Env> +) => Channel = core.concatAll /** * Concat sequentially a channel of channels. @@ -330,33 +349,33 @@ export const concatAll: ( * @category constructors */ export const concatAllWith: < - Env, - InErr, - InElem, - InDone, - OutErr, OutElem, - OutDone, - OutDone2, - OutDone3, - Env2, - InErr2, InElem2, + OutErr2, + InErr2, + OutDone, InDone2, - OutErr2 + Env2, + InElem, + OutErr, + InErr, + OutDone2, + InDone, + Env, + OutDone3 >( channels: Channel< - Env, - InErr, + Channel, InElem, - InDone, OutErr, - Channel, - OutDone2 + InErr, + OutDone2, + InDone, + Env >, f: (o: OutDone, o1: OutDone) => OutDone, g: (o: OutDone, o2: OutDone2) => OutDone3 -) => Channel = +) => Channel = core.concatAllWith /** @@ -369,15 +388,15 @@ export const concatAllWith: < * @category utils */ export const concatMap: { - ( - f: (o: OutElem) => Channel + ( + f: (o: OutElem) => Channel ): ( - self: Channel - ) => Channel + self: Channel + ) => Channel ( - self: Channel, - f: (o: OutElem) => Channel - ): Channel + self: Channel, + f: (o: OutElem) => Channel + ): Channel } = channel.concatMap /** @@ -392,35 +411,35 @@ export const concatMap: { * @category utils */ export const concatMapWith: { - ( - f: (o: OutElem) => Channel, + ( + f: (o: OutElem) => Channel, g: (o: OutDone, o1: OutDone) => OutDone, h: (o: OutDone, o2: OutDone2) => OutDone3 ): ( - self: Channel - ) => Channel + self: Channel + ) => Channel < - Env, - InErr, + OutElem, InElem, - InDone, OutErr, - OutElem, - OutElem2, - OutDone, + InErr, OutDone2, - OutDone3, - Env2, - InErr2, + InDone, + Env, + OutElem2, InElem2, + OutErr2, + InErr2, + OutDone, InDone2, - OutErr2 + Env2, + OutDone3 >( - self: Channel, - f: (o: OutElem) => Channel, + self: Channel, + f: (o: OutElem) => Channel, g: (o: OutDone, o1: OutDone) => OutDone, h: (o: OutDone, o2: OutDone2) => OutDone3 - ): Channel + ): Channel } = core.concatMapWith /** @@ -435,8 +454,8 @@ export const concatMapWith: { * @category utils */ export const concatMapWithCustom: { - ( - f: (o: OutElem) => Channel, + ( + f: (o: OutElem) => Channel, g: (o: OutDone, o1: OutDone) => OutDone, h: (o: OutDone, o2: OutDone2) => OutDone3, onPull: ( @@ -444,34 +463,34 @@ export const concatMapWithCustom: { ) => UpstreamPullStrategy.UpstreamPullStrategy, onEmit: (elem: OutElem2) => ChildExecutorDecision.ChildExecutorDecision ): ( - self: Channel - ) => Channel + self: Channel + ) => Channel < - Env, - InErr, + OutElem, InElem, - InDone, OutErr, - OutElem, - OutElem2, - OutDone, + InErr, OutDone2, - OutDone3, - Env2, - InErr2, + InDone, + Env, + OutElem2, InElem2, + OutErr2, + InErr2, + OutDone, InDone2, - OutErr2 + Env2, + OutDone3 >( - self: Channel, - f: (o: OutElem) => Channel, + self: Channel, + f: (o: OutElem) => Channel, g: (o: OutDone, o1: OutDone) => OutDone, h: (o: OutDone, o2: OutDone2) => OutDone3, onPull: ( upstreamPullRequest: UpstreamPullRequest.UpstreamPullRequest ) => UpstreamPullStrategy.UpstreamPullStrategy, onEmit: (elem: OutElem2) => ChildExecutorDecision.ChildExecutorDecision - ): Channel + ): Channel } = core.concatMapWithCustom /** @@ -482,15 +501,15 @@ export const concatMapWithCustom: { * @category utils */ export const collect: { - ( + ( pf: (o: OutElem) => Option.Option - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, pf: (o: OutElem) => Option.Option - ): Channel + ): Channel } = channel.collect /** @@ -501,17 +520,17 @@ export const collect: { * @since 2.0.0 * @category utils */ -export const concatOut: ( +export const concatOut: ( self: Channel< - Env, - InErr, + Channel, InElem, - InDone, OutErr, - Channel, - OutDone + InErr, + OutDone, + InDone, + Env > -) => Channel = channel.concatOut +) => Channel = channel.concatOut /** * Returns a new channel which is the same as this one but applies the given @@ -523,13 +542,13 @@ export const concatOut: ( export const mapInput: { ( f: (a: InDone0) => InDone - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, f: (a: InDone0) => InDone - ): Channel + ): Channel } = channel.mapInput /** @@ -540,15 +559,15 @@ export const mapInput: { * @category utils */ export const mapInputEffect: { - ( + ( f: (i: InDone0) => Effect.Effect - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, f: (i: InDone0) => Effect.Effect - ): Channel + ): Channel } = channel.mapInputEffect /** @@ -561,13 +580,13 @@ export const mapInputEffect: { export const mapInputError: { ( f: (a: InErr0) => InErr - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, f: (a: InErr0) => InErr - ): Channel + ): Channel } = channel.mapInputError /** @@ -578,15 +597,15 @@ export const mapInputError: { * @category utils */ export const mapInputErrorEffect: { - ( + ( f: (error: InErr0) => Effect.Effect - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, f: (error: InErr0) => Effect.Effect - ): Channel + ): Channel } = channel.mapInputErrorEffect /** @@ -599,13 +618,13 @@ export const mapInputErrorEffect: { export const mapInputIn: { ( f: (a: InElem0) => InElem - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, f: (a: InElem0) => InElem - ): Channel + ): Channel } = channel.mapInputIn /** @@ -616,15 +635,15 @@ export const mapInputIn: { * @category utils */ export const mapInputInEffect: { - ( + ( f: (a: InElem0) => Effect.Effect - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, f: (a: InElem0) => Effect.Effect - ): Channel + ): Channel } = channel.mapInputInEffect /** @@ -639,9 +658,9 @@ export const mapInputInEffect: { * @since 2.0.0 * @category utils */ -export const doneCollect: ( - self: Channel -) => Channel, OutDone]> = channel.doneCollect +export const doneCollect: ( + self: Channel +) => Channel, OutDone], InDone, Env> = channel.doneCollect /** * Returns a new channel which reads all the elements from upstream's output @@ -650,9 +669,9 @@ export const doneCollect: * @since 2.0.0 * @category utils */ -export const drain: ( - self: Channel -) => Channel = channel.drain +export const drain: ( + self: Channel +) => Channel = channel.drain /** * Returns a new channel which connects the given `AsyncInputProducer` as @@ -664,13 +683,13 @@ export const drain: ( export const embedInput: { ( input: SingleProducerAsyncInput.AsyncInputProducer - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, input: SingleProducerAsyncInput.AsyncInputProducer - ): Channel + ): Channel } = core.embedInput /** @@ -680,9 +699,9 @@ export const embedInput: { * @since 2.0.0 * @category utils */ -export const emitCollect: ( - self: Channel -) => Channel, OutDone], void> = channel.emitCollect +export const emitCollect: ( + self: Channel +) => Channel<[Chunk.Chunk, OutDone], InElem, OutErr, InErr, void, InDone, Env> = channel.emitCollect /** * Returns a new channel with an attached finalizer. The finalizer is @@ -693,15 +712,15 @@ export const emitCollect: * @category utils */ export const ensuring: { - ( + ( finalizer: Effect.Effect - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, finalizer: Effect.Effect - ): Channel + ): Channel } = channel.ensuring /** @@ -713,15 +732,15 @@ export const ensuring: { * @category utils */ export const ensuringWith: { - ( + ( finalizer: (e: Exit.Exit) => Effect.Effect - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, finalizer: (e: Exit.Exit) => Effect.Effect - ): Channel + ): Channel } = core.ensuringWith /** @@ -730,7 +749,7 @@ export const ensuringWith: { * @since 2.0.0 * @category context */ -export const context: () => Channel> = +export const context: () => Channel, unknown, Env> = channel.context /** @@ -741,7 +760,7 @@ export const context: () => Channel( f: (env: Context.Context) => OutDone -) => Channel = channel.contextWith +) => Channel = channel.contextWith /** * Accesses the context of the channel in the context of a channel. @@ -749,9 +768,9 @@ export const contextWith: ( * @since 2.0.0 * @category context */ -export const contextWithChannel: ( - f: (env: Context.Context) => Channel -) => Channel = channel.contextWithChannel +export const contextWithChannel: ( + f: (env: Context.Context) => Channel +) => Channel = channel.contextWithChannel /** * Accesses the context of the channel in the context of an effect. @@ -759,9 +778,9 @@ export const contextWithChannel: ( +export const contextWithEffect: ( f: (env: Context.Context) => Effect.Effect -) => Channel = channel.contextWithEffect +) => Channel = channel.contextWithEffect /** * Constructs a channel that fails immediately with the specified error. @@ -769,7 +788,7 @@ export const contextWithEffect: ( * @since 2.0.0 * @category constructors */ -export const fail: (error: E) => Channel = core.fail +export const fail: (error: E) => Channel = core.fail /** * Constructs a channel that succeeds immediately with the specified lazily @@ -778,8 +797,7 @@ export const fail: (error: E) => Channel(evaluate: LazyArg) => Channel = - core.failSync +export const failSync: (evaluate: LazyArg) => Channel = core.failSync /** * Constructs a channel that fails immediately with the specified `Cause`. @@ -787,7 +805,7 @@ export const failSync: (evaluate: LazyArg) => Channel(cause: Cause.Cause) => Channel = +export const failCause: (cause: Cause.Cause) => Channel = core.failCause /** @@ -799,7 +817,7 @@ export const failCause: (cause: Cause.Cause) => Channel( evaluate: LazyArg> -) => Channel = core.failCauseSync +) => Channel = core.failCauseSync /** * Returns a new channel, which sequentially combines this channel, together @@ -812,30 +830,30 @@ export const failCauseSync: ( * @category sequencing */ export const flatMap: { - ( - f: (d: OutDone) => Channel - ): ( - self: Channel + ( + f: (d: OutDone) => Channel + ): ( + self: Channel ) => Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1 | OutErr, - OutElem1 | OutElem, - OutDone2 + InErr & InErr1, + OutDone2, + InDone & InDone1, + Env1 | Env > - ( - self: Channel, - f: (d: OutDone) => Channel + ( + self: Channel, + f: (d: OutDone) => Channel ): Channel< - Env | Env1, - InErr & InErr1, + OutElem | OutElem1, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem | OutElem1, - OutDone2 + InErr & InErr1, + OutDone2, + InDone & InDone1, + Env | Env1 > } = core.flatMap @@ -848,37 +866,37 @@ export const flatMap: { * @category sequencing */ export const flatten: < - Env, - InErr, + OutElem, InElem, - InDone, OutErr, - OutElem, - Env1, - InErr1, + InErr, + OutElem1, InElem1, - InDone1, OutErr1, - OutElem1, - OutDone2 + InErr1, + OutDone2, + InDone1, + Env1, + InDone, + Env >( self: Channel< - Env, - InErr, + OutElem, InElem, - InDone, OutErr, - OutElem, - Channel + InErr, + Channel, + InDone, + Env > ) => Channel< - Env | Env1, - InErr & InErr1, + OutElem | OutElem1, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem | OutElem1, - OutDone2 + InErr & InErr1, + OutDone2, + InDone & InDone1, + Env1 | Env > = channel.flatten /** @@ -889,74 +907,74 @@ export const flatten: < */ export const foldChannel: { < - Env1, - Env2, - InErr1, - InErr2, - InElem1, - InElem2, - InDone1, - InDone2, OutErr, - OutErr1, - OutErr2, OutElem1, - OutElem2, - OutDone, + InElem1, + OutErr1, + InErr1, OutDone1, - OutDone2 + InDone1, + Env1, + OutDone, + OutElem2, + InElem2, + OutErr2, + InErr2, + OutDone2, + InDone2, + Env2 >( options: { - readonly onFailure: (error: OutErr) => Channel - readonly onSuccess: (done: OutDone) => Channel + readonly onFailure: (error: OutErr) => Channel + readonly onSuccess: (done: OutDone) => Channel } ): ( - self: Channel + self: Channel ) => Channel< - Env1 | Env2 | Env, - InErr & InErr1 & InErr2, + OutElem1 | OutElem2 | OutElem, InElem & InElem1 & InElem2, - InDone & InDone1 & InDone2, OutErr1 | OutErr2, - OutElem1 | OutElem2 | OutElem, - OutDone1 | OutDone2 + InErr & InErr1 & InErr2, + OutDone1 | OutDone2, + InDone & InDone1 & InDone2, + Env1 | Env2 | Env > < - Env, - InErr, + OutElem, InElem, + OutErr, + InErr, + OutDone, InDone, - OutElem, - Env1, - Env2, - InErr1, - InErr2, + Env, + OutElem1, InElem1, - InElem2, - InDone1, - InDone2, - OutErr, OutErr1, - OutErr2, - OutElem1, - OutElem2, - OutDone, + InErr1, OutDone1, - OutDone2 + InDone1, + Env1, + OutElem2, + InElem2, + OutErr2, + InErr2, + OutDone2, + InDone2, + Env2 >( - self: Channel, + self: Channel, options: { - readonly onFailure: (error: OutErr) => Channel - readonly onSuccess: (done: OutDone) => Channel + readonly onFailure: (error: OutErr) => Channel + readonly onSuccess: (done: OutDone) => Channel } ): Channel< - Env | Env1 | Env2, - InErr & InErr1 & InErr2, + OutElem | OutElem1 | OutElem2, InElem & InElem1 & InElem2, - InDone & InDone1 & InDone2, OutErr1 | OutErr2, - OutElem | OutElem1 | OutElem2, - OutDone1 | OutDone2 + InErr & InErr1 & InErr2, + OutDone1 | OutDone2, + InDone & InDone1 & InDone2, + Env | Env1 | Env2 > } = channel.foldChannel @@ -968,78 +986,78 @@ export const foldChannel: { */ export const foldCauseChannel: { < - Env1, - Env2, - InErr1, - InErr2, - InElem1, - InElem2, - InDone1, - InDone2, OutErr, - OutErr2, - OutErr3, OutElem1, - OutElem2, - OutDone, + InElem1, + OutErr2, + InErr1, OutDone2, - OutDone3 + InDone1, + Env1, + OutDone, + OutElem2, + InElem2, + OutErr3, + InErr2, + OutDone3, + InDone2, + Env2 >( options: { readonly onFailure: ( c: Cause.Cause - ) => Channel - readonly onSuccess: (o: OutDone) => Channel + ) => Channel + readonly onSuccess: (o: OutDone) => Channel } ): ( - self: Channel + self: Channel ) => Channel< - Env1 | Env2 | Env, - InErr & InErr1 & InErr2, + OutElem1 | OutElem2 | OutElem, InElem & InElem1 & InElem2, - InDone & InDone1 & InDone2, OutErr2 | OutErr3, - OutElem1 | OutElem2 | OutElem, - OutDone2 | OutDone3 + InErr & InErr1 & InErr2, + OutDone2 | OutDone3, + InDone & InDone1 & InDone2, + Env1 | Env2 | Env > < - Env, - InErr, + OutElem, InElem, + OutErr, + InErr, + OutDone, InDone, - OutElem, - Env1, - Env2, - InErr1, - InErr2, + Env, + OutElem1, InElem1, - InElem2, - InDone1, - InDone2, - OutErr, OutErr2, - OutErr3, - OutElem1, - OutElem2, - OutDone, + InErr1, OutDone2, - OutDone3 + InDone1, + Env1, + OutElem2, + InElem2, + OutErr3, + InErr2, + OutDone3, + InDone2, + Env2 >( - self: Channel, + self: Channel, options: { readonly onFailure: ( c: Cause.Cause - ) => Channel - readonly onSuccess: (o: OutDone) => Channel + ) => Channel + readonly onSuccess: (o: OutDone) => Channel } ): Channel< - Env | Env1 | Env2, - InErr & InErr1 & InErr2, + OutElem | OutElem1 | OutElem2, InElem & InElem1 & InElem2, - InDone & InDone1 & InDone2, OutErr2 | OutErr3, - OutElem | OutElem1 | OutElem2, - OutDone2 | OutDone3 + InErr & InErr1 & InErr2, + OutDone2 | OutDone3, + InDone & InDone1 & InDone2, + Env | Env1 | Env2 > } = core.foldCauseChannel @@ -1051,7 +1069,7 @@ export const foldCauseChannel: { */ export const fromEffect: ( effect: Effect.Effect -) => Channel = core.fromEffect +) => Channel = core.fromEffect /** * Constructs a channel from an `Either`. @@ -1059,7 +1077,7 @@ export const fromEffect: ( * @since 2.0.0 * @category constructors */ -export const fromEither: (either: Either.Either) => Channel = +export const fromEither: (either: Either.Either) => Channel = channel.fromEither /** @@ -1070,7 +1088,7 @@ export const fromEither: (either: Either.Either) => Channel( input: SingleProducerAsyncInput.AsyncInputConsumer -) => Channel = channel.fromInput +) => Channel = channel.fromInput /** * Construct a `Channel` from a `PubSub`. @@ -1078,9 +1096,9 @@ export const fromInput: ( * @since 2.0.0 * @category constructors */ -export const fromPubSub: ( +export const fromPubSub: ( pubsub: PubSub.PubSub, Elem>> -) => Channel = channel.fromPubSub +) => Channel = channel.fromPubSub /** * Construct a `Channel` from a `PubSub` within a scoped effect. @@ -1088,10 +1106,9 @@ export const fromPubSub: ( * @since 2.0.0 * @category constructors */ -export const fromPubSubScoped: ( +export const fromPubSubScoped: ( pubsub: PubSub.PubSub, Elem>> -) => Effect.Effect, never, Scope.Scope> = - channel.fromPubSubScoped +) => Effect.Effect, never, Scope.Scope> = channel.fromPubSubScoped /** * Construct a `Channel` from an `Option`. @@ -1101,7 +1118,7 @@ export const fromPubSubScoped: ( */ export const fromOption: ( option: Option.Option -) => Channel, never, A> = channel.fromOption +) => Channel, unknown, A, unknown> = channel.fromOption /** * Construct a `Channel` from a `Queue`. @@ -1109,15 +1126,15 @@ export const fromOption: ( * @since 2.0.0 * @category constructors */ -export const fromQueue: ( +export const fromQueue: ( queue: Queue.Dequeue, Elem>> -) => Channel = channel.fromQueue +) => Channel = channel.fromQueue /** * @since 2.0.0 * @category constructors */ -export const identity: () => Channel = channel.identityChannel +export const identity: () => Channel = channel.identityChannel /** * Returns a new channel, which is the same as this one, except it will be @@ -1132,15 +1149,15 @@ export const identity: () => Channel( + ( effect: Effect.Effect - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, effect: Effect.Effect - ): Channel + ): Channel } = channel.interruptWhen /** @@ -1155,15 +1172,15 @@ export const interruptWhen: { * @category utils */ export const interruptWhenDeferred: { - ( + ( deferred: Deferred.Deferred - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, deferred: Deferred.Deferred - ): Channel + ): Channel } = channel.interruptWhenDeferred /** @@ -1177,13 +1194,13 @@ export const interruptWhenDeferred: { export const map: { ( f: (out: OutDone) => OutDone2 - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, f: (out: OutDone) => OutDone2 - ): Channel + ): Channel } = channel.map /** @@ -1195,15 +1212,15 @@ export const map: { * @category mapping */ export const mapEffect: { - ( + ( f: (o: OutDone) => Effect.Effect - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, f: (o: OutDone) => Effect.Effect - ): Channel + ): Channel } = channel.mapEffect /** @@ -1217,13 +1234,13 @@ export const mapEffect: { export const mapError: { ( f: (err: OutErr) => OutErr2 - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, f: (err: OutErr) => OutErr2 - ): Channel + ): Channel } = channel.mapError /** @@ -1236,13 +1253,13 @@ export const mapError: { export const mapErrorCause: { ( f: (cause: Cause.Cause) => Cause.Cause - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, f: (cause: Cause.Cause) => Cause.Cause - ): Channel + ): Channel } = channel.mapErrorCause /** @@ -1254,13 +1271,13 @@ export const mapErrorCause: { export const mapOut: { ( f: (o: OutElem) => OutElem2 - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, f: (o: OutElem) => OutElem2 - ): Channel + ): Channel } = channel.mapOut /** @@ -1271,15 +1288,15 @@ export const mapOut: { * @category mapping */ export const mapOutEffect: { - ( + ( f: (o: OutElem) => Effect.Effect - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, f: (o: OutElem) => Effect.Effect - ): Channel + ): Channel } = channel.mapOutEffect /** @@ -1291,17 +1308,17 @@ export const mapOutEffect: { * @category mapping */ export const mapOutEffectPar: { - ( + ( f: (o: OutElem) => Effect.Effect, n: number - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, f: (o: OutElem) => Effect.Effect, n: number - ): Channel + ): Channel } = channel.mapOutEffectPar /** @@ -1314,34 +1331,34 @@ export const mergeAll: ( readonly bufferSize?: number | undefined readonly mergeStrategy?: MergeStrategy.MergeStrategy | undefined } -) => ( +) => ( channels: Channel< - Env, - InErr, + Channel, InElem, - InDone, OutErr, - Channel, - unknown + InErr, + unknown, + InDone, + Env > -) => Channel = +) => Channel = channel.mergeAll /** * @since 2.0.0 * @category utils */ -export const mergeAllUnbounded: ( +export const mergeAllUnbounded: ( channels: Channel< - Env, - InErr, + Channel, InElem, - InDone, OutErr, - Channel, - unknown + InErr, + unknown, + InDone, + Env > -) => Channel = +) => Channel = channel.mergeAllUnbounded /** @@ -1349,30 +1366,30 @@ export const mergeAllUnbounded: ( channels: Channel< - Env, - InErr, + Channel, InElem, - InDone, OutErr, - Channel, - OutDone + InErr, + OutDone, + InDone, + Env >, f: (o1: OutDone, o2: OutDone) => OutDone -) => Channel = +) => Channel = channel.mergeAllUnboundedWith /** @@ -1385,18 +1402,18 @@ export const mergeAllWith: ( readonly bufferSize?: number | undefined readonly mergeStrategy?: MergeStrategy.MergeStrategy | undefined } -) => ( +) => ( channels: Channel< - Env, - InErr, + Channel, InElem, - InDone, OutErr, - Channel, - OutDone + InErr, + OutDone, + InDone, + Env >, f: (o1: OutDone, o2: OutDone) => OutDone -) => Channel = +) => Channel = channel.mergeAllWith /** @@ -1411,25 +1428,25 @@ export const mergeAllWith: ( * @category mapping */ export const mergeMap: { - ( - f: (outElem: OutElem) => Channel, + ( + f: (outElem: OutElem) => Channel, options: { readonly concurrency: number | "unbounded" readonly bufferSize?: number | undefined readonly mergeStrategy?: MergeStrategy.MergeStrategy | undefined } - ): ( - self: Channel - ) => Channel - ( - self: Channel, - f: (outElem: OutElem) => Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, + f: (outElem: OutElem) => Channel, options: { readonly concurrency: number | "unbounded" readonly bufferSize?: number | undefined readonly mergeStrategy?: MergeStrategy.MergeStrategy | undefined } - ): Channel + ): Channel } = channel.mergeMap /** @@ -1442,29 +1459,29 @@ export const mergeMap: { export const mergeOut: { ( n: number - ): ( + ): ( self: Channel< - Env, - InErr, + Channel, InElem, - InDone, OutErr, - Channel, - OutDone + InErr, + OutDone, + InDone, + Env > - ) => Channel - ( + ) => Channel + ( self: Channel< - Env, - InErr, + Channel, InElem, - InDone, OutErr, - Channel, - OutDone + InErr, + OutDone, + InDone, + Env >, n: number - ): Channel + ): Channel } = channel.mergeOut /** @@ -1480,30 +1497,30 @@ export const mergeOutWith: { ( n: number, f: (o1: OutDone1, o2: OutDone1) => OutDone1 - ): ( + ): ( self: Channel< - Env, - InErr, + Channel, InElem, - InDone, OutErr, - Channel, - OutDone1 + InErr, + OutDone1, + InDone, + Env > - ) => Channel - ( + ) => Channel + ( self: Channel< - Env, - InErr, + Channel, InElem, - InDone, OutErr, - Channel, - OutDone1 + InErr, + OutDone1, + InDone, + Env >, n: number, f: (o1: OutDone1, o2: OutDone1) => OutDone1 - ): Channel + ): Channel } = channel.mergeOutWith /** @@ -1516,9 +1533,9 @@ export const mergeOutWith: { * @category utils */ export const mergeWith: { - ( + ( options: { - readonly other: Channel + readonly other: Channel readonly onSelfDone: ( exit: Exit.Exit ) => MergeDecision.MergeDecision @@ -1527,39 +1544,39 @@ export const mergeWith: { ) => MergeDecision.MergeDecision } ): ( - self: Channel + self: Channel ) => Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr2 | OutErr3, - OutElem1 | OutElem, - OutDone2 | OutDone3 + InErr & InErr1, + OutDone2 | OutDone3, + InDone & InDone1, + Env1 | Env > < - Env, - InErr, + OutElem, InElem, + OutErr, + InErr, + OutDone, InDone, - OutElem, - Env1, - InErr1, + Env, + OutElem1, InElem1, - InDone1, - OutErr, OutErr1, - OutErr2, - OutErr3, - OutElem1, - OutDone, + InErr1, OutDone1, + InDone1, + Env1, + OutErr2, OutDone2, + OutErr3, OutDone3 >( - self: Channel, + self: Channel, options: { - readonly other: Channel + readonly other: Channel readonly onSelfDone: ( exit: Exit.Exit ) => MergeDecision.MergeDecision @@ -1568,13 +1585,13 @@ export const mergeWith: { ) => MergeDecision.MergeDecision } ): Channel< - Env | Env1, - InErr & InErr1, + OutElem | OutElem1, InElem & InElem1, - InDone & InDone1, OutErr2 | OutErr3, - OutElem | OutElem1, - OutDone2 | OutDone3 + InErr & InErr1, + OutDone2 | OutDone3, + InDone & InDone1, + Env | Env1 > } = channel.mergeWith @@ -1584,7 +1601,7 @@ export const mergeWith: { * @since 2.0.0 * @category constructors */ -export const never: Channel = channel.never +export const never: Channel = channel.never /** * Translates channel failure into death of the fiber, making all failures @@ -1596,13 +1613,13 @@ export const never: Channel( error: LazyArg - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, error: LazyArg - ): Channel + ): Channel } = channel.orDie /** @@ -1615,13 +1632,13 @@ export const orDie: { export const orDieWith: { ( f: (e: OutErr) => unknown - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, f: (e: OutErr) => unknown - ): Channel + ): Channel } = channel.orDieWith /** @@ -1633,30 +1650,30 @@ export const orDieWith: { * @category error handling */ export const orElse: { - ( - that: LazyArg> - ): ( - self: Channel + ( + that: LazyArg> + ): ( + self: Channel ) => Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1, - OutElem1 | OutElem, - OutDone1 | OutDone + InErr & InErr1, + OutDone1 | OutDone, + InDone & InDone1, + Env1 | Env > - ( - self: Channel, - that: LazyArg> + ( + self: Channel, + that: LazyArg> ): Channel< - Env | Env1, - InErr & InErr1, + OutElem | OutElem1, InElem & InElem1, - InDone & InDone1, OutErr1, - OutElem | OutElem1, - OutDone | OutDone1 + InErr & InErr1, + OutDone | OutDone1, + InDone & InDone1, + Env | Env1 > } = channel.orElse @@ -1670,15 +1687,15 @@ export const orElse: { * @category utils */ export const pipeTo: { - ( - that: Channel - ): ( - self: Channel - ) => Channel - ( - self: Channel, - that: Channel - ): Channel + ( + that: Channel + ): ( + self: Channel + ) => Channel + ( + self: Channel, + that: Channel + ): Channel } = core.pipeTo /** @@ -1690,15 +1707,15 @@ export const pipeTo: { * @category utils */ export const pipeToOrFail: { - ( - that: Channel - ): ( - self: Channel - ) => Channel - ( - self: Channel, - that: Channel - ): Channel + ( + that: Channel + ): ( + self: Channel + ) => Channel + ( + self: Channel, + that: Channel + ): Channel } = channel.pipeToOrFail /** @@ -1711,13 +1728,13 @@ export const pipeToOrFail: { export const provideContext: { ( env: Context.Context - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, env: Context.Context - ): Channel + ): Channel } = core.provideContext /** @@ -1727,15 +1744,15 @@ export const provideContext: { * @category context */ export const provideLayer: { - ( + ( layer: Layer.Layer - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, layer: Layer.Layer - ): Channel + ): Channel } = channel.provideLayer /** @@ -1748,13 +1765,13 @@ export const provideLayer: { export const mapInputContext: { ( f: (env: Context.Context) => Context.Context - ): ( - self: Channel - ) => Channel - ( - self: Channel, + ): ( + self: Channel + ) => Channel + ( + self: Channel, f: (env: Context.Context) => Context.Context - ): Channel + ): Channel } = channel.mapInputContext /** @@ -1765,15 +1782,15 @@ export const mapInputContext: { * @category context */ export const provideSomeLayer: { - ( + ( layer: Layer.Layer - ): ( - self: Channel - ) => Channel, InErr, InElem, InDone, OutErr2 | OutErr, OutElem, OutDone> - ( - self: Channel, + ): ( + self: Channel + ) => Channel> + ( + self: Channel, layer: Layer.Layer - ): Channel, InErr, InElem, InDone, OutErr | OutErr2, OutElem, OutDone> + ): Channel> } = channel.provideSomeLayer /** @@ -1787,62 +1804,62 @@ export const provideService: { >( tag: T, service: Context.Tag.Service - ): ( - self: Channel - ) => Channel>, InErr, InElem, InDone, OutErr, OutElem, OutDone> - >( - self: Channel, + ): ( + self: Channel + ) => Channel>> + >( + self: Channel, tag: T, service: Context.Tag.Service - ): Channel>, InErr, InElem, InDone, OutErr, OutElem, OutDone> + ): Channel>> } = channel.provideService /** * @since 2.0.0 * @category constructors */ -export const read: () => Channel, never, In> = channel.read +export const read: () => Channel, unknown, In, unknown> = channel.read /** * @since 2.0.0 * @category constructors */ -export const readOrFail: (error: E) => Channel = core.readOrFail +export const readOrFail: (error: E) => Channel = core.readOrFail /** * @since 2.0.0 * @category constructors */ export const readWith: < - Env, - InErr, InElem, - InDone, - OutErr, OutElem, + OutErr, + InErr, OutDone, - Env2, - OutErr2, + InDone, + Env, OutElem2, + OutErr2, OutDone2, - Env3, - OutErr3, + Env2, OutElem3, - OutDone3 + OutErr3, + OutDone3, + Env3 >( options: { - readonly onInput: (input: InElem) => Channel - readonly onFailure: (error: InErr) => Channel - readonly onDone: (done: InDone) => Channel + readonly onInput: (input: InElem) => Channel + readonly onFailure: (error: InErr) => Channel + readonly onDone: (done: InDone) => Channel } ) => Channel< - Env | Env2 | Env3, - InErr, + OutElem | OutElem2 | OutElem3, InElem, - InDone, OutErr | OutErr2 | OutErr3, - OutElem | OutElem2 | OutElem3, - OutDone | OutDone2 | OutDone3 + InErr, + OutDone | OutDone2 | OutDone3, + InDone, + Env | Env2 | Env3 > = core.readWith /** @@ -1850,35 +1867,35 @@ export const readWith: < * @category constructors */ export const readWithCause: < - Env, - InErr, InElem, - InDone, - OutErr, OutElem, + OutErr, + InErr, OutDone, - Env2, - OutErr2, + InDone, + Env, OutElem2, + OutErr2, OutDone2, - Env3, - OutErr3, + Env2, OutElem3, - OutDone3 + OutErr3, + OutDone3, + Env3 >( options: { - readonly onInput: (input: InElem) => Channel - readonly onFailure: (cause: Cause.Cause) => Channel - readonly onDone: (done: InDone) => Channel + readonly onInput: (input: InElem) => Channel + readonly onFailure: (cause: Cause.Cause) => Channel + readonly onDone: (done: InDone) => Channel } ) => Channel< - Env | Env2 | Env3, - InErr, + OutElem | OutElem2 | OutElem3, InElem, - InDone, OutErr | OutErr2 | OutErr3, - OutElem | OutElem2 | OutElem3, - OutDone | OutDone2 | OutDone3 + InErr, + OutDone | OutDone2 | OutDone3, + InDone, + Env | Env2 | Env3 > = core.readWithCause /** @@ -1887,9 +1904,9 @@ export const readWithCause: < * @since 2.0.0 * @category utils */ -export const repeated: ( - self: Channel -) => Channel = channel.repeated +export const repeated: ( + self: Channel +) => Channel = channel.repeated /** * Runs a channel until the end is received. @@ -1897,8 +1914,8 @@ export const repeated: ( * @since 2.0.0 * @category destructors */ -export const run: ( - self: Channel +export const run: ( + self: Channel ) => Effect.Effect = channel.run /** @@ -1910,8 +1927,8 @@ export const run: ( * @since 2.0.0 * @category destructors */ -export const runCollect: ( - self: Channel +export const runCollect: ( + self: Channel ) => Effect.Effect<[Chunk.Chunk, OutDone], OutErr, Env> = channel.runCollect /** @@ -1920,8 +1937,8 @@ export const runCollect: ( * @since 2.0.0 * @category destructors */ -export const runDrain: ( - self: Channel +export const runDrain: ( + self: Channel ) => Effect.Effect = channel.runDrain /** @@ -1932,7 +1949,7 @@ export const runDrain: ( */ export const scoped: ( effect: Effect.Effect -) => Channel, unknown, unknown, unknown, E, A, unknown> = channel.scoped +) => Channel> = channel.scoped /** * Constructs a channel that succeeds immediately with the specified value. @@ -1940,7 +1957,7 @@ export const scoped: ( * @since 2.0.0 * @category constructors */ -export const succeed: (value: A) => Channel = core.succeed +export const succeed: (value: A) => Channel = core.succeed /** * Lazily constructs a channel from the given side effect. @@ -1948,9 +1965,9 @@ export const succeed: (value: A) => Channel( - evaluate: LazyArg> -) => Channel = core.suspend +export const suspend: ( + evaluate: LazyArg> +) => Channel = core.suspend /** * Constructs a channel that succeeds immediately with the specified lazy value. @@ -1960,7 +1977,7 @@ export const suspend: ( */ export const sync: ( evaluate: LazyArg -) => Channel = core.sync +) => Channel = core.sync /** * Converts a `Channel` to a `PubSub`. @@ -1968,9 +1985,9 @@ export const sync: ( * @since 2.0.0 * @category destructors */ -export const toPubSub: ( +export const toPubSub: ( pubsub: PubSub.PubSub, Elem>> -) => Channel = channel.toPubSub +) => Channel = channel.toPubSub /** * Returns a scoped `Effect` that can be used to repeatedly pull elements from @@ -1981,8 +1998,8 @@ export const toPubSub: ( * @since 2.0.0 * @category destructors */ -export const toPull: ( - self: Channel +export const toPull: ( + self: Channel ) => Effect.Effect, OutErr, Env>, never, Scope.Scope | Env> = channel.toPull @@ -1992,17 +2009,17 @@ export const toPull: ( * @since 2.0.0 * @category destructors */ -export const toQueue: ( +export const toQueue: ( queue: Queue.Enqueue, Elem>> -) => Channel = channel.toQueue +) => Channel = channel.toQueue /** Converts this channel to a `Sink`. * * @since 2.0.0 * @category destructors */ -export const toSink: ( - self: Channel, unknown, OutErr, Chunk.Chunk, OutDone> +export const toSink: ( + self: Channel, Chunk.Chunk, OutErr, InErr, OutDone, unknown, Env> ) => Sink.Sink = sink.channelToSink /** @@ -2011,15 +2028,15 @@ export const toSink: ( * @since 2.0.0 * @category destructors */ -export const toStream: ( - self: Channel, OutDone> +export const toStream: ( + self: Channel, unknown, OutErr, unknown, OutDone, unknown, Env> ) => Stream.Stream = stream.channelToStream /** * @since 2.0.0 * @category constructors */ -export const unit: Channel = core.unit +export const unit: Channel = core.unit /** * Makes a channel from an effect that returns a channel in case of success. @@ -2027,9 +2044,9 @@ export const unit: Channel * @since 2.0.0 * @category constructors */ -export const unwrap: ( - channel: Effect.Effect, E, R> -) => Channel = channel.unwrap +export const unwrap: ( + channel: Effect.Effect, E, R> +) => Channel = channel.unwrap /** * Makes a channel from a managed that returns a channel in case of success. @@ -2037,9 +2054,9 @@ export const unwrap: * @since 2.0.0 * @category constructors */ -export const unwrapScoped: ( - self: Effect.Effect, E, R> -) => Channel, InErr, InElem, InDone, E | OutErr, OutElem, OutDone> = channel.unwrapScoped +export const unwrapScoped: ( + self: Effect.Effect, E, R> +) => Channel> = channel.unwrapScoped /** * Updates a service in the context of this channel. @@ -2051,14 +2068,14 @@ export const updateService: { >( tag: T, f: (resource: Context.Tag.Service) => Context.Tag.Service - ): ( - self: Channel - ) => Channel - >( - self: Channel, + ): ( + self: Channel + ) => Channel + >( + self: Channel, tag: T, f: (resource: Context.Tag.Service) => Context.Tag.Service - ): Channel + ): Channel } = channel.updateService /** @@ -2076,12 +2093,12 @@ export const withSpan: { readonly parent?: Tracer.ParentSpan | undefined readonly root?: boolean | undefined readonly context?: Context.Context | undefined - } - ): ( - self: Channel - ) => Channel - ( - self: Channel, + } | undefined + ): ( + self: Channel + ) => Channel> + ( + self: Channel, name: string, options?: { readonly attributes?: Record | undefined @@ -2089,8 +2106,8 @@ export const withSpan: { readonly parent?: Tracer.ParentSpan | undefined readonly root?: boolean | undefined readonly context?: Context.Context | undefined - } - ): Channel + } | undefined + ): Channel> } = channel.withSpan /** @@ -2099,8 +2116,7 @@ export const withSpan: { * @since 2.0.0 * @category constructors */ -export const write: (out: OutElem) => Channel = - core.write +export const write: (out: OutElem) => Channel = core.write /** * Writes a sequence of values to the channel. @@ -2110,7 +2126,7 @@ export const write: (out: OutElem) => Channel>( ...outs: OutElems -) => Channel = channel.writeAll +) => Channel = channel.writeAll /** * Writes a `Chunk` of values to the channel. @@ -2120,7 +2136,7 @@ export const writeAll: >( */ export const writeChunk: ( outs: Chunk.Chunk -) => Channel = channel.writeChunk +) => Channel = channel.writeChunk /** * Returns a new channel that is the sequential composition of this channel @@ -2131,36 +2147,32 @@ export const writeChunk: ( * @category zipping */ export const zip: { - ( - that: Channel, - options?: { - readonly concurrent?: boolean | undefined - } - ): ( - self: Channel + ( + that: Channel, + options?: { readonly concurrent?: boolean | undefined } | undefined + ): ( + self: Channel ) => Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1 | OutErr, - OutElem1 | OutElem, - readonly [OutDone, OutDone1] + InErr & InErr1, + readonly [OutDone, OutDone1], + InDone & InDone1, + Env1 | Env > - ( - self: Channel, - that: Channel, - options?: { - readonly concurrent?: boolean | undefined - } + ( + self: Channel, + that: Channel, + options?: { readonly concurrent?: boolean | undefined } | undefined ): Channel< - Env | Env1, - InErr & InErr1, + OutElem | OutElem1, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem | OutElem1, - readonly [OutDone, OutDone1] + InErr & InErr1, + readonly [OutDone, OutDone1], + InDone & InDone1, + Env | Env1 > } = channel.zip @@ -2173,36 +2185,32 @@ export const zip: { * @category zipping */ export const zipLeft: { - ( - that: Channel, - options?: { - readonly concurrent?: boolean | undefined - } - ): ( - self: Channel + ( + that: Channel, + options?: { readonly concurrent?: boolean | undefined } | undefined + ): ( + self: Channel ) => Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1 | OutErr, - OutElem1 | OutElem, - OutDone + InErr & InErr1, + OutDone, + InDone & InDone1, + Env1 | Env > - ( - self: Channel, - that: Channel, - options?: { - readonly concurrent?: boolean | undefined - } + ( + self: Channel, + that: Channel, + options?: { readonly concurrent?: boolean | undefined } | undefined ): Channel< - Env | Env1, - InErr & InErr1, + OutElem | OutElem1, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem | OutElem1, - OutDone + InErr & InErr1, + OutDone, + InDone & InDone1, + Env | Env1 > } = channel.zipLeft @@ -2216,35 +2224,35 @@ export const zipLeft: { */ export const zipRight: { ( - that: Channel, + that: Channel, options?: { readonly concurrent?: boolean | undefined } ): ( - self: Channel + self: Channel ) => Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1 | OutErr, - OutElem1 | OutElem, - OutDone1 + InErr & InErr1, + OutDone1, + InDone & InDone1, + Env1 | Env > ( - self: Channel, - that: Channel, + self: Channel, + that: Channel, options?: { readonly concurrent?: boolean | undefined } ): Channel< - Env | Env1, - InErr & InErr1, + OutElem | OutElem1, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem | OutElem1, - OutDone1 + InErr & InErr1, + OutDone1, + InDone & InDone1, + Env | Env1 > } = channel.zipRight diff --git a/packages/effect/src/Sink.ts b/packages/effect/src/Sink.ts index f371b0c086..7fb2b07cd3 100644 --- a/packages/effect/src/Sink.ts +++ b/packages/effect/src/Sink.ts @@ -981,7 +981,7 @@ export const flatMap: { * @category constructors */ export const fromChannel: ( - channel: Channel.Channel, unknown, E, Chunk.Chunk, Z> + channel: Channel.Channel, Chunk.Chunk, E, never, Z, unknown, R> ) => Sink = internal.fromChannel /** @@ -992,7 +992,7 @@ export const fromChannel: ( */ export const toChannel: ( self: Sink -) => Channel.Channel, unknown, E, Chunk.Chunk, Z> = internal.toChannel +) => Channel.Channel, Chunk.Chunk, E, never, Z, unknown, R> = internal.toChannel /** * Creates a single-value sink produced from an effect. diff --git a/packages/effect/src/Stream.ts b/packages/effect/src/Stream.ts index 1d1ca393d6..d4a76893f7 100644 --- a/packages/effect/src/Stream.ts +++ b/packages/effect/src/Stream.ts @@ -1424,7 +1424,7 @@ export const fromAsyncIterable: (iterable: AsyncIterable, onError: (e: * @category constructors */ export const fromChannel: ( - channel: Channel.Channel, unknown> + channel: Channel.Channel, unknown, E, unknown, unknown, unknown, R> ) => Stream = internal.fromChannel /** @@ -1435,7 +1435,7 @@ export const fromChannel: ( */ export const toChannel: ( stream: Stream -) => Channel.Channel, unknown> = internal.toChannel +) => Channel.Channel, unknown, E, unknown, unknown, unknown, R> = internal.toChannel /** * Creates a stream from a `Chunk` of values. @@ -2522,11 +2522,11 @@ export const pipeThrough: { */ export const pipeThroughChannel: { ( - channel: Channel.Channel, unknown, E2, Chunk.Chunk, unknown> + channel: Channel.Channel, Chunk.Chunk, E2, E, unknown, unknown, R2> ): (self: Stream) => Stream ( self: Stream, - channel: Channel.Channel, unknown, E2, Chunk.Chunk, unknown> + channel: Channel.Channel, Chunk.Chunk, E2, E, unknown, unknown, R2> ): Stream } = internal.pipeThroughChannel @@ -2539,11 +2539,11 @@ export const pipeThroughChannel: { */ export const pipeThroughChannelOrFail: { ( - chan: Channel.Channel, unknown, E2, Chunk.Chunk, unknown> + chan: Channel.Channel, Chunk.Chunk, E2, E, unknown, unknown, R2> ): (self: Stream) => Stream ( self: Stream, - chan: Channel.Channel, unknown, E2, Chunk.Chunk, unknown> + chan: Channel.Channel, Chunk.Chunk, E2, E, unknown, unknown, R2> ): Stream } = internal.pipeThroughChannelOrFail diff --git a/packages/effect/src/internal/channel.ts b/packages/effect/src/internal/channel.ts index 08ac577962..6b3e504ca1 100644 --- a/packages/effect/src/internal/channel.ts +++ b/packages/effect/src/internal/channel.ts @@ -35,11 +35,11 @@ import * as ChannelStateOpCodes from "./opCodes/channelState.js" import * as tracer from "./tracer.js" /** @internal */ -export const acquireUseRelease = ( +export const acquireUseRelease = ( acquire: Effect.Effect, - use: (a: Acquired) => Channel.Channel, + use: (a: Acquired) => Channel.Channel, release: (a: Acquired, exit: Exit.Exit) => Effect.Effect -): Channel.Channel => +): Channel.Channel => core.flatMap( core.fromEffect( Ref.make< @@ -65,37 +65,37 @@ export const acquireUseRelease = ( value: OutDone2 - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, value: OutDone2 - ) => Channel.Channel ->(2, ( - self: Channel.Channel, + ) => Channel.Channel +>(2, ( + self: Channel.Channel, value: OutDone2 -): Channel.Channel => map(self, () => value)) +): Channel.Channel => map(self, () => value)) /** @internal */ -export const asUnit = ( - self: Channel.Channel -): Channel.Channel => map(self, constVoid) +export const asUnit = ( + self: Channel.Channel +): Channel.Channel => map(self, constVoid) /** @internal */ -export const buffer = ( +export const buffer = ( options: { readonly empty: InElem readonly isEmpty: Predicate readonly ref: Ref.Ref } -): Channel.Channel => - core.suspend(() => { +): Channel.Channel => + core.suspend(() => { const doBuffer = ( empty: InElem, isEmpty: Predicate, ref: Ref.Ref - ): Channel.Channel => + ): Channel.Channel => unwrap( Ref.modify(ref, (inElem) => isEmpty(inElem) ? @@ -123,10 +123,10 @@ export const buffer = ( }) /** @internal */ -export const bufferChunk = ( +export const bufferChunk = ( ref: Ref.Ref> -): Channel.Channel, InDone, InErr, Chunk.Chunk, InDone> => - buffer, InDone>({ +): Channel.Channel, Chunk.Chunk, InErr, InErr, InDone, InDone> => + buffer({ empty: Chunk.empty(), isEmpty: Chunk.isEmpty, ref @@ -134,44 +134,44 @@ export const bufferChunk = ( /** @internal */ export const catchAll = dual< - ( - f: (error: OutErr) => Channel.Channel - ) => ( - self: Channel.Channel + ( + f: (error: OutErr) => Channel.Channel + ) => ( + self: Channel.Channel ) => Channel.Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1, - OutElem1 | OutElem, - OutDone1 | OutDone + InErr & InErr1, + OutDone1 | OutDone, + InDone & InDone1, + Env1 | Env >, - ( - self: Channel.Channel, - f: (error: OutErr) => Channel.Channel + ( + self: Channel.Channel, + f: (error: OutErr) => Channel.Channel ) => Channel.Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1, - OutElem1 | OutElem, - OutDone1 | OutDone + InErr & InErr1, + OutDone1 | OutDone, + InDone & InDone1, + Env1 | Env > >( 2, - ( - self: Channel.Channel, - f: (error: OutErr) => Channel.Channel + ( + self: Channel.Channel, + f: (error: OutErr) => Channel.Channel ): Channel.Channel< - Env | Env1, - InErr & InErr1, + OutElem | OutElem1, InElem & InElem1, - InDone & InDone1, OutErr1, - OutElem | OutElem1, - OutDone | OutDone1 + InErr & InErr1, + OutDone | OutDone1, + InDone & InDone1, + Env | Env1 > => core.catchAllCause(self, (cause) => Either.match(Cause.failureOrCause(cause), { @@ -182,60 +182,60 @@ export const catchAll = dual< /** @internal */ export const concatMap = dual< - ( - f: (o: OutElem) => Channel.Channel + ( + f: (o: OutElem) => Channel.Channel ) => ( - self: Channel.Channel + self: Channel.Channel ) => Channel.Channel< - Env2 | Env, - InErr & InErr2, + OutElem2, InElem & InElem2, - InDone & InDone2, OutErr2 | OutErr, - OutElem2, - unknown + InErr & InErr2, + unknown, + InDone & InDone2, + Env2 | Env >, ( - self: Channel.Channel, - f: (o: OutElem) => Channel.Channel + self: Channel.Channel, + f: (o: OutElem) => Channel.Channel ) => Channel.Channel< - Env2 | Env, - InErr & InErr2, + OutElem2, InElem & InElem2, - InDone & InDone2, OutErr2 | OutErr, - OutElem2, - unknown + InErr & InErr2, + unknown, + InDone & InDone2, + Env2 | Env > >(2, ( - self: Channel.Channel, - f: (o: OutElem) => Channel.Channel + self: Channel.Channel, + f: (o: OutElem) => Channel.Channel ): Channel.Channel< - Env | Env2, - InErr & InErr2, + OutElem2, InElem & InElem2, - InDone & InDone2, OutErr | OutErr2, - OutElem2, - unknown + InErr & InErr2, + unknown, + InDone & InDone2, + Env | Env2 > => core.concatMapWith(self, f, () => void 0, () => void 0)) /** @internal */ export const collect = dual< - ( + ( pf: (o: OutElem) => Option.Option - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, pf: (o: OutElem) => Option.Option - ) => Channel.Channel ->(2, ( - self: Channel.Channel, + ) => Channel.Channel +>(2, ( + self: Channel.Channel, pf: (o: OutElem) => Option.Option -): Channel.Channel => { - const collector: Channel.Channel = core +): Channel.Channel => { + const collector: Channel.Channel = core .readWith({ onInput: (out) => Option.match(pf(out), { @@ -249,34 +249,34 @@ export const collect = dual< }) /** @internal */ -export const concatOut = ( +export const concatOut = ( self: Channel.Channel< - Env, - InErr, + Channel.Channel, InElem, - InDone, OutErr, - Channel.Channel, - OutDone + InErr, + OutDone, + InDone, + Env > -): Channel.Channel => core.concatAll(self) +): Channel.Channel => core.concatAll(self) /** @internal */ export const mapInput = dual< ( f: (a: InDone0) => InDone - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, f: (a: InDone0) => InDone - ) => Channel.Channel ->(2, ( - self: Channel.Channel, + ) => Channel.Channel +>(2, ( + self: Channel.Channel, f: (a: InDone0) => InDone -): Channel.Channel => { - const reader: Channel.Channel = core.readWith({ +): Channel.Channel => { + const reader: Channel.Channel = core.readWith({ onInput: (inElem: InElem) => core.flatMap(core.write(inElem), () => reader), onFailure: core.fail, onDone: (done: InDone0) => core.succeedNow(f(done)) @@ -286,20 +286,20 @@ export const mapInput = dual< /** @internal */ export const mapInputEffect = dual< - ( + ( f: (i: InDone0) => Effect.Effect - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, f: (i: InDone0) => Effect.Effect - ) => Channel.Channel ->(2, ( - self: Channel.Channel, + ) => Channel.Channel +>(2, ( + self: Channel.Channel, f: (i: InDone0) => Effect.Effect -): Channel.Channel => { - const reader: Channel.Channel = core.readWith({ +): Channel.Channel => { + const reader: Channel.Channel = core.readWith({ onInput: (inElem) => core.flatMap(core.write(inElem), () => reader), onFailure: core.fail, onDone: (done) => core.fromEffect(f(done)) @@ -311,18 +311,18 @@ export const mapInputEffect = dual< export const mapInputError = dual< ( f: (a: InErr0) => InErr - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, f: (a: InErr0) => InErr - ) => Channel.Channel ->(2, ( - self: Channel.Channel, + ) => Channel.Channel +>(2, ( + self: Channel.Channel, f: (a: InErr0) => InErr -): Channel.Channel => { - const reader: Channel.Channel = core.readWith({ +): Channel.Channel => { + const reader: Channel.Channel = core.readWith({ onInput: (inElem: InElem) => core.flatMap(core.write(inElem), () => reader), onFailure: (error) => core.fail(f(error)), onDone: core.succeedNow @@ -332,20 +332,20 @@ export const mapInputError = dual< /** @internal */ export const mapInputErrorEffect = dual< - ( + ( f: (error: InErr0) => Effect.Effect - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, f: (error: InErr0) => Effect.Effect - ) => Channel.Channel ->(2, ( - self: Channel.Channel, + ) => Channel.Channel +>(2, ( + self: Channel.Channel, f: (error: InErr0) => Effect.Effect -): Channel.Channel => { - const reader: Channel.Channel = core.readWith({ +): Channel.Channel => { + const reader: Channel.Channel = core.readWith({ onInput: (inElem) => core.flatMap(core.write(inElem), () => reader), onFailure: (error) => core.fromEffect(f(error)), onDone: core.succeedNow @@ -357,18 +357,18 @@ export const mapInputErrorEffect = dual< export const mapInputIn = dual< ( f: (a: InElem0) => InElem - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, f: (a: InElem0) => InElem - ) => Channel.Channel ->(2, ( - self: Channel.Channel, + ) => Channel.Channel +>(2, ( + self: Channel.Channel, f: (a: InElem0) => InElem -): Channel.Channel => { - const reader: Channel.Channel = core.readWith({ +): Channel.Channel => { + const reader: Channel.Channel = core.readWith({ onInput: (inElem) => core.flatMap(core.write(f(inElem)), () => reader), onFailure: core.fail, onDone: core.succeedNow @@ -378,20 +378,20 @@ export const mapInputIn = dual< /** @internal */ export const mapInputInEffect = dual< - ( + ( f: (a: InElem0) => Effect.Effect - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, f: (a: InElem0) => Effect.Effect - ) => Channel.Channel ->(2, ( - self: Channel.Channel, + ) => Channel.Channel +>(2, ( + self: Channel.Channel, f: (a: InElem0) => Effect.Effect -): Channel.Channel => { - const reader: Channel.Channel = core.readWith({ +): Channel.Channel => { + const reader: Channel.Channel = core.readWith({ onInput: (inElem) => core.flatMap(core.flatMap(core.fromEffect(f(inElem)), core.write), () => reader), onFailure: core.fail, onDone: core.succeedNow @@ -400,17 +400,9 @@ export const mapInputInEffect = dual< }) /** @internal */ -export const doneCollect = ( - self: Channel.Channel -): Channel.Channel< - Env, - InErr, - InElem, - InDone, - OutErr, - never, - [Chunk.Chunk, OutDone] -> => +export const doneCollect = ( + self: Channel.Channel +): Channel.Channel, OutDone], InDone, Env> => core.suspend(() => { const builder: Array = [] return pipe( @@ -422,7 +414,7 @@ export const doneCollect = ( builder: Array -): Channel.Channel => { +): Channel.Channel => { return core.readWith({ onInput: (outElem) => core.flatMap( @@ -437,10 +429,10 @@ const doneCollectReader = ( } /** @internal */ -export const drain = ( - self: Channel.Channel -): Channel.Channel => { - const drainer: Channel.Channel = core +export const drain = ( + self: Channel.Channel +): Channel.Channel => { + const drainer: Channel.Channel = core .readWithCause({ onInput: () => drainer, onFailure: core.failCause, @@ -450,214 +442,207 @@ export const drain = ( } /** @internal */ -export const emitCollect = ( - self: Channel.Channel -): Channel.Channel, OutDone], void> => +export const emitCollect = ( + self: Channel.Channel +): Channel.Channel<[Chunk.Chunk, OutDone], InElem, OutErr, InErr, void, InDone, Env> => core.flatMap(doneCollect(self), core.write) /** @internal */ export const ensuring = dual< - ( + ( finalizer: Effect.Effect - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, finalizer: Effect.Effect - ) => Channel.Channel + ) => Channel.Channel >(2, ( - self: Channel.Channel, + self: Channel.Channel, finalizer: Effect.Effect -): Channel.Channel => +): Channel.Channel => core.ensuringWith(self, () => finalizer)) /** @internal */ -export const context = (): Channel.Channel< - Env, - unknown, - unknown, - unknown, - never, - never, - Context.Context -> => core.fromEffect(Effect.context()) +export const context = (): Channel.Channel, unknown, Env> => + core.fromEffect(Effect.context()) /** @internal */ export const contextWith = ( f: (env: Context.Context) => OutDone -): Channel.Channel => map(context(), f) +): Channel.Channel => map(context(), f) /** @internal */ export const contextWithChannel = < Env, - Env1, - InErr, + OutElem, InElem, - InDone, OutErr, - OutElem, - OutDone + InErr, + OutDone, + InDone, + Env1 >( - f: (env: Context.Context) => Channel.Channel -): Channel.Channel => core.flatMap(context(), f) + f: (env: Context.Context) => Channel.Channel +): Channel.Channel => core.flatMap(context(), f) /** @internal */ -export const contextWithEffect = ( +export const contextWithEffect = ( f: (env: Context.Context) => Effect.Effect -): Channel.Channel => mapEffect(context(), f) +): Channel.Channel => mapEffect(context(), f) /** @internal */ export const flatten = < - Env, - InErr, + OutElem, InElem, - InDone, OutErr, - OutElem, - Env1, - InErr1, + InErr, + OutElem1, InElem1, - InDone1, OutErr1, - OutElem1, - OutDone2 + InErr1, + OutDone2, + InDone1, + Env1, + InDone, + Env >( self: Channel.Channel< - Env, - InErr, + OutElem, InElem, - InDone, OutErr, - OutElem, - Channel.Channel + InErr, + Channel.Channel, + InDone, + Env > ): Channel.Channel< - Env | Env1, - InErr & InErr1, + OutElem | OutElem1, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem | OutElem1, - OutDone2 + InErr & InErr1, + OutDone2, + InDone & InDone1, + Env | Env1 > => core.flatMap(self, identity) /** @internal */ export const foldChannel = dual< < - Env1, - Env2, - InErr1, - InErr2, - InElem1, - InElem2, - InDone1, - InDone2, OutErr, - OutErr1, - OutErr2, OutElem1, - OutElem2, - OutDone, + InElem1, + OutErr1, + InErr1, OutDone1, - OutDone2 + InDone1, + Env1, + OutDone, + OutElem2, + InElem2, + OutErr2, + InErr2, + OutDone2, + InDone2, + Env2 >( options: { readonly onFailure: ( error: OutErr - ) => Channel.Channel + ) => Channel.Channel readonly onSuccess: ( done: OutDone - ) => Channel.Channel + ) => Channel.Channel } ) => ( - self: Channel.Channel + self: Channel.Channel ) => Channel.Channel< - Env1 | Env2 | Env, - InErr & InErr1 & InErr2, + OutElem1 | OutElem2 | OutElem, InElem & InElem1 & InElem2, - InDone & InDone1 & InDone2, OutErr1 | OutErr2, - OutElem1 | OutElem2 | OutElem, - OutDone1 | OutDone2 + InErr & InErr1 & InErr2, + OutDone1 | OutDone2, + InDone & InDone1 & InDone2, + Env1 | Env2 | Env >, < - Env, - InErr, + OutElem, InElem, + OutErr, + InErr, + OutDone, InDone, - OutElem, - Env1, - Env2, - InErr1, - InErr2, + Env, + OutElem1, InElem1, - InElem2, - InDone1, - InDone2, - OutErr, OutErr1, - OutErr2, - OutElem1, - OutElem2, - OutDone, + InErr1, OutDone1, - OutDone2 + InDone1, + Env1, + OutElem2, + InElem2, + OutErr2, + InErr2, + OutDone2, + InDone2, + Env2 >( - self: Channel.Channel, + self: Channel.Channel, options: { readonly onFailure: ( error: OutErr - ) => Channel.Channel + ) => Channel.Channel readonly onSuccess: ( done: OutDone - ) => Channel.Channel + ) => Channel.Channel } ) => Channel.Channel< - Env1 | Env2 | Env, - InErr & InErr1 & InErr2, + OutElem1 | OutElem2 | OutElem, InElem & InElem1 & InElem2, - InDone & InDone1 & InDone2, OutErr1 | OutErr2, - OutElem1 | OutElem2 | OutElem, - OutDone1 | OutDone2 + InErr & InErr1 & InErr2, + OutDone1 | OutDone2, + InDone & InDone1 & InDone2, + Env1 | Env2 | Env > >(2, < - Env, - InErr, + OutElem, InElem, + OutErr, + InErr, + OutDone, InDone, - OutElem, - Env1, - Env2, - InErr1, - InErr2, + Env, + OutElem1, InElem1, - InElem2, - InDone1, - InDone2, - OutErr, OutErr1, - OutErr2, - OutElem1, - OutElem2, - OutDone, + InErr1, OutDone1, - OutDone2 + InDone1, + Env1, + OutElem2, + InElem2, + OutErr2, + InErr2, + OutDone2, + InDone2, + Env2 >( - self: Channel.Channel, + self: Channel.Channel, options: { - readonly onFailure: (error: OutErr) => Channel.Channel - readonly onSuccess: (done: OutDone) => Channel.Channel + readonly onFailure: (error: OutErr) => Channel.Channel + readonly onSuccess: (done: OutDone) => Channel.Channel } ): Channel.Channel< - Env | Env1 | Env2, - InErr & InErr1 & InErr2, + OutElem | OutElem2 | OutElem1, InElem & InElem1 & InElem2, - InDone & InDone1 & InDone2, OutErr2 | OutErr1, - OutElem | OutElem2 | OutElem1, - OutDone2 | OutDone1 + InErr & InErr1 & InErr2, + OutDone2 | OutDone1, + InDone & InDone1 & InDone2, + Env | Env1 | Env2 > => core.foldCauseChannel(self, { onFailure: (cause) => { @@ -677,13 +662,13 @@ export const foldChannel = dual< /** @internal */ export const fromEither = ( either: Either.Either -): Channel.Channel => +): Channel.Channel => core.suspend(() => Either.match(either, { onLeft: core.fail, onRight: core.succeed })) /** @internal */ export const fromInput = ( input: SingleProducerAsyncInput.AsyncInputConsumer -): Channel.Channel => +): Channel.Channel => unwrap( input.takeWith( core.failCause, @@ -693,21 +678,21 @@ export const fromInput = ( ) /** @internal */ -export const fromPubSub = ( +export const fromPubSub = ( pubsub: PubSub.PubSub, Elem>> -): Channel.Channel => +): Channel.Channel => unwrapScoped(Effect.map(PubSub.subscribe(pubsub), fromQueue)) /** @internal */ -export const fromPubSubScoped = ( +export const fromPubSubScoped = ( pubsub: PubSub.PubSub, Elem>> -): Effect.Effect, never, Scope.Scope> => +): Effect.Effect, never, Scope.Scope> => Effect.map(PubSub.subscribe(pubsub), fromQueue) /** @internal */ export const fromOption = ( option: Option.Option -): Channel.Channel, never, A> => +): Channel.Channel, unknown, A, unknown> => core.suspend(() => Option.match(option, { onNone: () => core.fail(Option.none()), @@ -716,14 +701,14 @@ export const fromOption = ( ) /** @internal */ -export const fromQueue = ( +export const fromQueue = ( queue: Queue.Dequeue, Elem>> -): Channel.Channel => core.suspend(() => fromQueueInternal(queue)) +): Channel.Channel => core.suspend(() => fromQueueInternal(queue)) /** @internal */ -const fromQueueInternal = ( +const fromQueueInternal = ( queue: Queue.Dequeue, Elem>> -): Channel.Channel => +): Channel.Channel => pipe( core.fromEffect(Queue.take(queue)), core.flatMap(Either.match({ @@ -734,42 +719,34 @@ const fromQueueInternal = ( onRight: (elem) => core.flatMap( core.write(elem), - () => fromQueueInternal(queue) + () => fromQueueInternal(queue) ) })) ) /** @internal */ -export const identityChannel = (): Channel.Channel => +export const identityChannel = (): Channel.Channel => core.readWith({ - onInput: (input: Elem) => core.flatMap(core.write(input), () => identityChannel()), + onInput: (input: Elem) => core.flatMap(core.write(input), () => identityChannel()), onFailure: core.fail, onDone: core.succeedNow }) /** @internal */ export const interruptWhen = dual< - ( + ( effect: Effect.Effect - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, effect: Effect.Effect - ) => Channel.Channel ->(2, ( - self: Channel.Channel, + ) => Channel.Channel +>(2, ( + self: Channel.Channel, effect: Effect.Effect -): Channel.Channel< - Env1 | Env, - InErr, - InElem, - InDone, - OutErr | OutErr1, - OutElem, - OutDone | OutDone1 -> => +): Channel.Channel => mergeWith(self, { other: core.fromEffect(effect), onSelfDone: (selfDone) => mergeDecision.Done(Effect.suspend(() => selfDone)), @@ -778,104 +755,104 @@ export const interruptWhen = dual< /** @internal */ export const interruptWhenDeferred = dual< - ( + ( deferred: Deferred.Deferred - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, deferred: Deferred.Deferred - ) => Channel.Channel + ) => Channel.Channel >(2, ( - self: Channel.Channel, + self: Channel.Channel, deferred: Deferred.Deferred -): Channel.Channel => +): Channel.Channel => interruptWhen(self, Deferred.await(deferred))) /** @internal */ export const map = dual< ( f: (out: OutDone) => OutDone2 - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, f: (out: OutDone) => OutDone2 - ) => Channel.Channel + ) => Channel.Channel >(2, ( - self: Channel.Channel, + self: Channel.Channel, f: (out: OutDone) => OutDone2 -): Channel.Channel => +): Channel.Channel => core.flatMap(self, (a) => core.sync(() => f(a)))) /** @internal */ export const mapEffect = dual< - ( + ( f: (o: OutDone) => Effect.Effect - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, f: (o: OutDone) => Effect.Effect - ) => Channel.Channel ->(2, ( - self: Channel.Channel, + ) => Channel.Channel +>(2, ( + self: Channel.Channel, f: (o: OutDone) => Effect.Effect -): Channel.Channel => +): Channel.Channel => core.flatMap(self, (z) => core.fromEffect(f(z)))) /** @internal */ export const mapError = dual< ( f: (err: OutErr) => OutErr2 - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, f: (err: OutErr) => OutErr2 - ) => Channel.Channel ->(2, ( - self: Channel.Channel, + ) => Channel.Channel +>(2, ( + self: Channel.Channel, f: (err: OutErr) => OutErr2 -): Channel.Channel => mapErrorCause(self, Cause.map(f))) +): Channel.Channel => mapErrorCause(self, Cause.map(f))) /** @internal */ export const mapErrorCause = dual< ( f: (cause: Cause.Cause) => Cause.Cause - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, f: (cause: Cause.Cause) => Cause.Cause - ) => Channel.Channel ->(2, ( - self: Channel.Channel, + ) => Channel.Channel +>(2, ( + self: Channel.Channel, f: (cause: Cause.Cause) => Cause.Cause -): Channel.Channel => +): Channel.Channel => core.catchAllCause(self, (cause) => core.failCause(f(cause)))) /** @internal */ export const mapOut = dual< ( f: (o: OutElem) => OutElem2 - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, f: (o: OutElem) => OutElem2 - ) => Channel.Channel ->(2, ( - self: Channel.Channel, + ) => Channel.Channel +>(2, ( + self: Channel.Channel, f: (o: OutElem) => OutElem2 -): Channel.Channel => { - const reader: Channel.Channel = core +): Channel.Channel => { + const reader: Channel.Channel = core .readWith({ onInput: (outElem) => core.flatMap(core.write(f(outElem)), () => reader), onFailure: core.fail, @@ -886,20 +863,20 @@ export const mapOut = dual< /** @internal */ export const mapOutEffect = dual< - ( + ( f: (o: OutElem) => Effect.Effect - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, f: (o: OutElem) => Effect.Effect - ) => Channel.Channel ->(2, ( - self: Channel.Channel, + ) => Channel.Channel +>(2, ( + self: Channel.Channel, f: (o: OutElem) => Effect.Effect -): Channel.Channel => { - const reader: Channel.Channel = core +): Channel.Channel => { + const reader: Channel.Channel = core .readWithCause({ onInput: (outElem) => pipe( @@ -915,22 +892,22 @@ export const mapOutEffect = dual< /** @internal */ export const mapOutEffectPar = dual< - ( + ( f: (o: OutElem) => Effect.Effect, n: number - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, f: (o: OutElem) => Effect.Effect, n: number - ) => Channel.Channel ->(3, ( - self: Channel.Channel, + ) => Channel.Channel +>(3, ( + self: Channel.Channel, f: (o: OutElem) => Effect.Effect, n: number -): Channel.Channel => +): Channel.Channel => pipe( Effect.gen(function*($) { const queue = yield* $( @@ -1000,15 +977,7 @@ export const mapOutEffectPar = dual< return queue }), Effect.map((queue) => { - const consumer: Channel.Channel< - Env1, - unknown, - unknown, - unknown, - OutErr | OutErr1, - OutElem1, - OutDone - > = unwrap( + const consumer: Channel.Channel = unwrap( Effect.matchCause(Effect.flatten(Queue.take(queue)), { onFailure: core.failCause, onSuccess: Either.match({ @@ -1031,104 +1000,104 @@ export const mergeAll = ( } ) => { return < - Env, - Env1, - InErr, - InErr1, - InElem, + OutElem, InElem1, - InDone, + OutErr1, + InErr1, InDone1, + Env1, + InElem, OutErr, - OutErr1, - OutElem + InErr, + InDone, + Env >( channels: Channel.Channel< - Env, - InErr, + Channel.Channel, InElem, - InDone, OutErr, - Channel.Channel, - unknown + InErr, + unknown, + InDone, + Env > ): Channel.Channel< - Env | Env1, - InErr & InErr1, + OutElem, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem, - unknown + InErr & InErr1, + unknown, + InDone & InDone1, + Env | Env1 > => mergeAllWith(options)(channels, constVoid) } /** @internal */ export const mergeAllUnbounded = < - Env, - Env1, - InErr, - InErr1, - InElem, + OutElem, InElem1, - InDone, + OutErr1, + InErr1, InDone1, + Env1, + InElem, OutErr, - OutErr1, - OutElem + InErr, + InDone, + Env >( channels: Channel.Channel< - Env, - InErr, + Channel.Channel, InElem, - InDone, OutErr, - Channel.Channel, - unknown + InErr, + unknown, + InDone, + Env > ): Channel.Channel< - Env | Env1, - InErr & InErr1, + OutElem, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem, - unknown + InErr & InErr1, + unknown, + InDone & InDone1, + Env | Env1 > => mergeAllWith({ concurrency: "unbounded" })(channels, constVoid) /** @internal */ export const mergeAllUnboundedWith = < - Env, - Env1, - InErr, - InErr1, - InElem, + OutElem, InElem1, - InDone, + OutErr1, + InErr1, + OutDone, InDone1, + Env1, + InElem, OutErr, - OutErr1, - OutElem, - OutDone + InErr, + InDone, + Env >( channels: Channel.Channel< - Env, - InErr, + Channel.Channel, InElem, - InDone, OutErr, - Channel.Channel, - OutDone + InErr, + OutDone, + InDone, + Env >, f: (o1: OutDone, o2: OutDone) => OutDone ): Channel.Channel< - Env | Env1, - InErr & InErr1, + OutElem, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem, - OutDone + InErr & InErr1, + OutDone, + InDone & InDone1, + Env | Env1 > => mergeAllWith({ concurrency: "unbounded" })(channels, f) /** @internal */ @@ -1143,38 +1112,25 @@ export const mergeAllWith = ( readonly mergeStrategy?: MergeStrategy.MergeStrategy | undefined } ) => -< - Env, - Env1, - InErr, - InErr1, - InElem, - InElem1, - InDone, - InDone1, - OutErr, - OutErr1, - OutElem, - OutDone ->( +( channels: Channel.Channel< - Env, - InErr, + Channel.Channel, InElem, - InDone, OutErr, - Channel.Channel, - OutDone + InErr, + OutDone, + InDone, + Env >, f: (o1: OutDone, o2: OutDone) => OutDone ): Channel.Channel< - Env | Env1, - InErr & InErr1, + OutElem, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem, - OutDone + InErr & InErr1, + OutDone, + InDone & InDone1, + Env | Env1 > => pipe( Effect.gen(function*($) { @@ -1335,15 +1291,7 @@ export const mergeAllWith = ( return [queue, input] as const }), Effect.map(([queue, input]) => { - const consumer: Channel.Channel< - Env | Env1, - unknown, - unknown, - unknown, - OutErr | OutErr1, - OutElem, - OutDone - > = pipe( + const consumer: Channel.Channel = pipe( Queue.take(queue), Effect.flatten, Effect.matchCause({ @@ -1362,121 +1310,121 @@ export const mergeAllWith = ( /** @internal */ export const mergeMap = dual< - ( - f: (outElem: OutElem) => Channel.Channel, + ( + f: (outElem: OutElem) => Channel.Channel, options: { readonly concurrency: number | "unbounded" readonly bufferSize?: number | undefined readonly mergeStrategy?: MergeStrategy.MergeStrategy | undefined } - ) => ( - self: Channel.Channel + ) => ( + self: Channel.Channel ) => Channel.Channel< - Env1 | Env, - InErr & InErr1, + OutElem1, InElem & InElem1, - InDone & InDone1, OutErr1 | OutErr, - OutElem1, - unknown + InErr & InErr1, + unknown, + InDone & InDone1, + Env1 | Env >, - ( - self: Channel.Channel, - f: (outElem: OutElem) => Channel.Channel, + ( + self: Channel.Channel, + f: (outElem: OutElem) => Channel.Channel, options: { readonly concurrency: number | "unbounded" readonly bufferSize?: number | undefined readonly mergeStrategy?: MergeStrategy.MergeStrategy | undefined } ) => Channel.Channel< - Env1 | Env, - InErr & InErr1, + OutElem1, InElem & InElem1, - InDone & InDone1, OutErr1 | OutErr, - OutElem1, - unknown + InErr & InErr1, + unknown, + InDone & InDone1, + Env1 | Env > ->(3, ( - self: Channel.Channel, - f: (outElem: OutElem) => Channel.Channel, +>(3, ( + self: Channel.Channel, + f: (outElem: OutElem) => Channel.Channel, options: { readonly concurrency: number | "unbounded" readonly bufferSize?: number | undefined readonly mergeStrategy?: MergeStrategy.MergeStrategy | undefined } ): Channel.Channel< - Env | Env1, - InErr & InErr1, + OutElem1, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem1, - unknown + InErr & InErr1, + unknown, + InDone & InDone1, + Env | Env1 > => mergeAll(options)(mapOut(self, f))) /** @internal */ export const mergeOut = dual< ( n: number - ) => ( + ) => ( self: Channel.Channel< - Env, - InErr, + Channel.Channel, InElem, - InDone, OutErr, - Channel.Channel, - OutDone + InErr, + OutDone, + InDone, + Env > ) => Channel.Channel< - Env | Env1, - InErr & InErr1, + OutElem1, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem1, - unknown + InErr & InErr1, + unknown, + InDone & InDone1, + Env | Env1 >, - ( + ( self: Channel.Channel< - Env, - InErr, + Channel.Channel, InElem, - InDone, OutErr, - Channel.Channel, - OutDone + InErr, + OutDone, + InDone, + Env >, n: number ) => Channel.Channel< - Env | Env1, - InErr & InErr1, + OutElem1, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem1, - unknown + InErr & InErr1, + unknown, + InDone & InDone1, + Env | Env1 > ->(2, ( +>(2, ( self: Channel.Channel< - Env, - InErr, + Channel.Channel, InElem, - InDone, OutErr, - Channel.Channel, - OutDone + InErr, + OutDone, + InDone, + Env >, n: number ): Channel.Channel< - Env | Env1, - InErr & InErr1, + OutElem1, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem1, - unknown + InErr & InErr1, + unknown, + InDone & InDone1, + Env | Env1 > => mergeAll({ concurrency: n })(mapOut(self, identity))) /** @internal */ @@ -1484,73 +1432,73 @@ export const mergeOutWith = dual< ( n: number, f: (o1: OutDone1, o2: OutDone1) => OutDone1 - ) => ( + ) => ( self: Channel.Channel< - Env, - InErr, + Channel.Channel, InElem, - InDone, OutErr, - Channel.Channel, - OutDone1 + InErr, + OutDone1, + InDone, + Env > ) => Channel.Channel< - Env | Env1, - InErr & InErr1, + OutElem1, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem1, - OutDone1 + InErr & InErr1, + OutDone1, + InDone & InDone1, + Env | Env1 >, - ( + ( self: Channel.Channel< - Env, - InErr, + Channel.Channel, InElem, - InDone, OutErr, - Channel.Channel, - OutDone1 + InErr, + OutDone1, + InDone, + Env >, n: number, f: (o1: OutDone1, o2: OutDone1) => OutDone1 ) => Channel.Channel< - Env | Env1, - InErr & InErr1, + OutElem1, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem1, - OutDone1 + InErr & InErr1, + OutDone1, + InDone & InDone1, + Env | Env1 > ->(3, ( +>(3, ( self: Channel.Channel< - Env, - InErr, + Channel.Channel, InElem, - InDone, OutErr, - Channel.Channel, - OutDone1 + InErr, + OutDone1, + InDone, + Env >, n: number, f: (o1: OutDone1, o2: OutDone1) => OutDone1 ): Channel.Channel< - Env | Env1, - InErr & InErr1, + OutElem1, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem1, - OutDone1 + InErr & InErr1, + OutDone1, + InDone & InDone1, + Env | Env1 > => mergeAllWith({ concurrency: n })(mapOut(self, identity), f)) /** @internal */ export const mergeWith = dual< - ( + ( options: { - readonly other: Channel.Channel + readonly other: Channel.Channel readonly onSelfDone: ( exit: Exit.Exit ) => MergeDecision.MergeDecision @@ -1559,39 +1507,39 @@ export const mergeWith = dual< ) => MergeDecision.MergeDecision } ) => ( - self: Channel.Channel + self: Channel.Channel ) => Channel.Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr2 | OutErr3, - OutElem1 | OutElem, - OutDone2 | OutDone3 + InErr & InErr1, + OutDone2 | OutDone3, + InDone & InDone1, + Env1 | Env >, < - Env, - InErr, + OutElem, InElem, + OutErr, + InErr, + OutDone, InDone, - OutElem, - Env1, - InErr1, + Env, + OutElem1, InElem1, - InDone1, - OutErr, OutErr1, - OutErr2, - OutErr3, - OutElem1, - OutDone, + InErr1, OutDone1, + InDone1, + Env1, + OutErr2, OutDone2, + OutErr3, OutDone3 >( - self: Channel.Channel, + self: Channel.Channel, options: { - readonly other: Channel.Channel + readonly other: Channel.Channel readonly onSelfDone: ( exit: Exit.Exit ) => MergeDecision.MergeDecision @@ -1600,37 +1548,37 @@ export const mergeWith = dual< ) => MergeDecision.MergeDecision } ) => Channel.Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr2 | OutErr3, - OutElem1 | OutElem, - OutDone2 | OutDone3 + InErr & InErr1, + OutDone2 | OutDone3, + InDone & InDone1, + Env1 | Env > >(2, < - Env, - InErr, + OutElem, InElem, + OutErr, + InErr, + OutDone, InDone, - OutElem, - Env1, - InErr1, + Env, + OutElem1, InElem1, - InDone1, - OutErr, OutErr1, - OutErr2, - OutErr3, - OutElem1, - OutDone, + InErr1, OutDone1, + InDone1, + Env1, + OutErr2, OutDone2, + OutErr3, OutDone3 >( - self: Channel.Channel, + self: Channel.Channel, options: { - readonly other: Channel.Channel + readonly other: Channel.Channel readonly onSelfDone: ( exit: Exit.Exit ) => MergeDecision.MergeDecision @@ -1639,13 +1587,13 @@ export const mergeWith = dual< ) => MergeDecision.MergeDecision } ): Channel.Channel< - Env1 | Env, - InErr & InErr1, + OutElem | OutElem1, InElem & InElem1, - InDone & InDone1, OutErr2 | OutErr3, - OutElem | OutElem1, - OutDone2 | OutDone3 + InErr & InErr1, + OutDone2 | OutDone3, + InDone & InDone1, + Env1 | Env > => unwrapScoped( Effect.flatMap( @@ -1699,13 +1647,13 @@ export const mergeWith = dual< ) => State ): Effect.Effect< Channel.Channel< - Env | Env1, + OutElem | OutElem1, unknown, + OutErr2 | OutErr3, unknown, + OutDone2 | OutDone3, unknown, - OutErr2 | OutErr3, - OutElem | OutElem1, - OutDone2 | OutDone3 + Env | Env1 >, never, Env | Env1 @@ -1720,13 +1668,13 @@ export const mergeWith = dual< > ): Effect.Effect< Channel.Channel< - Env | Env1, + OutElem | OutElem1, unknown, + OutErr2 | OutErr3, unknown, + OutDone2 | OutDone3, unknown, - OutErr2 | OutErr3, - OutElem | OutElem1, - OutDone2 | OutDone3 + Env | Env1 > > => { const op = decision as mergeDecision.Primitive @@ -1771,13 +1719,13 @@ export const mergeWith = dual< const go = ( state: State ): Channel.Channel< - Env | Env1, + OutElem | OutElem1, unknown, + OutErr2 | OutErr3, unknown, + OutDone2 | OutDone3, unknown, - OutErr2 | OutErr3, - OutElem | OutElem1, - OutDone2 | OutDone3 + Env | Env1 > => { switch (state._tag) { case MergeStateOpCodes.OP_BOTH_RUNNING: { @@ -1881,7 +1829,7 @@ export const mergeWith = dual< )) /** @internal */ -export const never: Channel.Channel = core.fromEffect( +export const never: Channel.Channel = core.fromEffect( Effect.never ) @@ -1889,99 +1837,99 @@ export const never: Channel.Channel( error: LazyArg - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, error: LazyArg - ) => Channel.Channel ->(2, ( - self: Channel.Channel, + ) => Channel.Channel +>(2, ( + self: Channel.Channel, error: LazyArg -): Channel.Channel => orDieWith(self, error)) +): Channel.Channel => orDieWith(self, error)) /** @internal */ export const orDieWith = dual< ( f: (e: OutErr) => unknown - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, f: (e: OutErr) => unknown - ) => Channel.Channel ->(2, ( - self: Channel.Channel, + ) => Channel.Channel +>(2, ( + self: Channel.Channel, f: (e: OutErr) => unknown -): Channel.Channel => +): Channel.Channel => catchAll(self, (e) => { throw f(e) - }) as Channel.Channel) + }) as Channel.Channel) /** @internal */ export const orElse = dual< - ( - that: LazyArg> - ) => ( - self: Channel.Channel + ( + that: LazyArg> + ) => ( + self: Channel.Channel ) => Channel.Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1, - OutElem1 | OutElem, - OutDone1 | OutDone + InErr & InErr1, + OutDone1 | OutDone, + InDone & InDone1, + Env1 | Env >, - ( - self: Channel.Channel, - that: LazyArg> + ( + self: Channel.Channel, + that: LazyArg> ) => Channel.Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1, - OutElem1 | OutElem, - OutDone1 | OutDone + InErr & InErr1, + OutDone1 | OutDone, + InDone & InDone1, + Env1 | Env > >( 2, ( - self: Channel.Channel, - that: LazyArg> + self: Channel.Channel, + that: LazyArg> ): Channel.Channel< - Env | Env1, - InErr & InErr1, + OutElem | OutElem1, InElem & InElem1, - InDone & InDone1, OutErr1, - OutElem | OutElem1, - OutDone | OutDone1 + InErr & InErr1, + OutDone | OutDone1, + InDone & InDone1, + Env | Env1 > => catchAll(self, that) ) /** @internal */ export const pipeToOrFail = dual< - ( - that: Channel.Channel - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, - that: Channel.Channel - ) => Channel.Channel ->(2, ( - self: Channel.Channel, - that: Channel.Channel -): Channel.Channel => + ( + that: Channel.Channel + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, + that: Channel.Channel + ) => Channel.Channel +>(2, ( + self: Channel.Channel, + that: Channel.Channel +): Channel.Channel => core.suspend(() => { let channelException: Channel.ChannelException | undefined = undefined - const reader: Channel.Channel = core + const reader: Channel.Channel = core .readWith({ onInput: (outElem) => core.flatMap(core.write(outElem), () => reader), onFailure: (outErr) => { @@ -1992,13 +1940,13 @@ export const pipeToOrFail = dual< }) const writer: Channel.Channel< - Env2, - OutErr2, OutElem2, - OutDone2, - OutErr2, OutElem2, - OutDone2 + OutErr2, + OutErr2, + OutDone2, + OutDone2, + Env2 > = core.readWithCause({ onInput: (outElem) => pipe(core.write(outElem), core.flatMap(() => writer)), onFailure: (cause) => @@ -2018,19 +1966,19 @@ export const provideService = dual< >( tag: T, service: Context.Tag.Service - ) => ( - self: Channel.Channel - ) => Channel.Channel>, InErr, InElem, InDone, OutErr, OutElem, OutDone>, - >( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel>>, + >( + self: Channel.Channel, tag: T, service: Context.Tag.Service - ) => Channel.Channel>, InErr, InElem, InDone, OutErr, OutElem, OutDone> ->(3, >( - self: Channel.Channel, + ) => Channel.Channel>> +>(3, >( + self: Channel.Channel, tag: T, service: Context.Tag.Service -): Channel.Channel>, InErr, InElem, InDone, OutErr, OutElem, OutDone> => { +): Channel.Channel>> => { return core.flatMap( context(), (context) => core.provideContext(self, Context.add(context, tag, service)) @@ -2039,91 +1987,84 @@ export const provideService = dual< /** @internal */ export const provideLayer = dual< - ( + ( layer: Layer.Layer - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, layer: Layer.Layer - ) => Channel.Channel ->(2, ( - self: Channel.Channel, + ) => Channel.Channel +>(2, ( + self: Channel.Channel, layer: Layer.Layer -): Channel.Channel => +): Channel.Channel => unwrapScoped(Effect.map(Layer.build(layer), (env) => core.provideContext(self, env)))) /** @internal */ export const mapInputContext = dual< ( f: (env: Context.Context) => Context.Context - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, f: (env: Context.Context) => Context.Context - ) => Channel.Channel ->(2, ( - self: Channel.Channel, + ) => Channel.Channel +>(2, ( + self: Channel.Channel, f: (env: Context.Context) => Context.Context -): Channel.Channel => +): Channel.Channel => contextWithChannel((context: Context.Context) => core.provideContext(self, f(context)))) /** @internal */ export const provideSomeLayer = dual< - ( + ( layer: Layer.Layer - ) => ( - self: Channel.Channel - ) => Channel.Channel, InErr, InElem, InDone, OutErr2 | OutErr, OutElem, OutDone>, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel>, + ( + self: Channel.Channel, layer: Layer.Layer - ) => Channel.Channel, InErr, InElem, InDone, OutErr2 | OutErr, OutElem, OutDone> ->(2, ( - self: Channel.Channel, + ) => Channel.Channel> +>(2, ( + self: Channel.Channel, layer: Layer.Layer -): Channel.Channel, InErr, InElem, InDone, OutErr | OutErr2, OutElem, OutDone> => +): Channel.Channel> => // @ts-expect-error provideLayer(self, Layer.merge(Layer.context>(), layer))) /** @internal */ -export const read = (): Channel.Channel< - never, - unknown, - In, - unknown, - Option.Option, - never, - In -> => core.readOrFail>(Option.none()) +export const read = (): Channel.Channel, unknown, In, unknown> => + core.readOrFail, In>(Option.none()) /** @internal */ -export const repeated = ( - self: Channel.Channel -): Channel.Channel => core.flatMap(self, () => repeated(self)) +export const repeated = ( + self: Channel.Channel +): Channel.Channel => core.flatMap(self, () => repeated(self)) /** @internal */ -export const run = ( - self: Channel.Channel +export const run = ( + self: Channel.Channel ): Effect.Effect => Effect.scoped(executor.runScoped(self)) /** @internal */ -export const runCollect = ( - self: Channel.Channel +export const runCollect = ( + self: Channel.Channel ): Effect.Effect<[Chunk.Chunk, OutDone], OutErr, Env> => executor.run(core.collectElements(self)) /** @internal */ -export const runDrain = ( - self: Channel.Channel +export const runDrain = ( + self: Channel.Channel ): Effect.Effect => executor.run(drain(self)) /** @internal */ export const scoped = ( effect: Effect.Effect -): Channel.Channel, unknown, unknown, unknown, E, A, unknown> => +): Channel.Channel> => unwrap( Effect.uninterruptibleMask((restore) => Effect.map(Scope.make(), (scope) => @@ -2140,38 +2081,38 @@ export const scoped = ( /** @internal */ export const service = >( tag: T -): Channel.Channel, unknown, unknown, unknown, never, never, Context.Tag.Service> => +): Channel.Channel, unknown, Context.Tag.Identifier> => core.fromEffect(tag) /** @internal */ export const serviceWith = >(tag: T) => ( f: (resource: Context.Tag.Service) => OutDone -): Channel.Channel, unknown, unknown, unknown, never, never, OutDone> => map(service(tag), f) +): Channel.Channel> => map(service(tag), f) /** @internal */ export const serviceWithChannel = >(tag: T) => ( - f: (resource: Context.Tag.Service) => Channel.Channel - ): Channel.Channel, InErr, InElem, InDone, OutErr, OutElem, OutDone> => + f: (resource: Context.Tag.Service) => Channel.Channel + ): Channel.Channel> => core.flatMap(service(tag), f) /** @internal */ export const serviceWithEffect = >(tag: T) => ( f: (resource: Context.Tag.Service) => Effect.Effect -): Channel.Channel, unknown, unknown, unknown, OutErr, never, OutDone> => +): Channel.Channel> => mapEffect(service(tag), f) /** @internal */ -export const toPubSub = ( +export const toPubSub = ( pubsub: PubSub.PubSub, Elem>> -): Channel.Channel => toQueue(pubsub) +): Channel.Channel => toQueue(pubsub) /** @internal */ -export const toPull = ( - self: Channel.Channel +export const toPull = ( + self: Channel.Channel ): Effect.Effect, OutErr, Env>, never, Env | Scope.Scope> => Effect.map( Effect.acquireRelease( @@ -2187,7 +2128,7 @@ export const toPull = ( /** @internal */ const interpretToPull = ( channelState: ChannelState.ChannelState, - exec: executor.ChannelExecutor + exec: executor.ChannelExecutor ): Effect.Effect, OutErr, Env> => { const state = channelState as ChannelState.Primitive switch (state._tag) { @@ -2218,14 +2159,14 @@ const interpretToPull = ( } /** @internal */ -export const toQueue = ( +export const toQueue = ( queue: Queue.Enqueue, Elem>> -): Channel.Channel => core.suspend(() => toQueueInternal(queue)) +): Channel.Channel => core.suspend(() => toQueueInternal(queue)) /** @internal */ const toQueueInternal = ( queue: Queue.Enqueue, Elem>> -): Channel.Channel => { +): Channel.Channel => { return core.readWithCause({ onInput: (elem) => core.flatMap( @@ -2238,14 +2179,14 @@ const toQueueInternal = ( } /** @internal */ -export const unwrap = ( - channel: Effect.Effect, E, R> -): Channel.Channel => flatten(core.fromEffect(channel)) +export const unwrap = ( + channel: Effect.Effect, E, R> +): Channel.Channel => flatten(core.fromEffect(channel)) /** @internal */ -export const unwrapScoped = ( - self: Effect.Effect, E, R> -): Channel.Channel, InErr, InElem, InDone, E | OutErr, OutElem, OutDone> => +export const unwrapScoped = ( + self: Effect.Effect, E, R> +): Channel.Channel> => core.concatAllWith( scoped(self), (d, _) => d, @@ -2257,19 +2198,19 @@ export const updateService = dual< >( tag: T, f: (resource: Context.Tag.Service) => Context.Tag.Service - ) => ( - self: Channel.Channel - ) => Channel.Channel, - >( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + >( + self: Channel.Channel, tag: T, f: (resource: Context.Tag.Service) => Context.Tag.Service - ) => Channel.Channel ->(3, >( - self: Channel.Channel, + ) => Channel.Channel +>(3, >( + self: Channel.Channel, tag: T, f: (resource: Context.Tag.Service) => Context.Tag.Service -): Channel.Channel => +): Channel.Channel => mapInputContext(self, (context: Context.Context) => Context.merge( context, @@ -2287,11 +2228,11 @@ export const withSpan = dual< readonly root?: boolean | undefined readonly context?: Context.Context | undefined } - ) => ( - self: Channel.Channel - ) => Channel.Channel, InErr, InElem, InDone, OutErr, OutElem, OutDone>, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel>, + ( + self: Channel.Channel, name: string, options?: { readonly attributes?: Record | undefined @@ -2300,7 +2241,7 @@ export const withSpan = dual< readonly root?: boolean | undefined readonly context?: Context.Context | undefined } - ) => Channel.Channel, InErr, InElem, InDone, OutErr, OutElem, OutDone> + ) => Channel.Channel> >(3, (self, name, options) => unwrapScoped( Effect.flatMap( @@ -2316,19 +2257,19 @@ export const withSpan = dual< /** @internal */ export const writeAll = ( ...outs: Array -): Channel.Channel => writeChunk(Chunk.fromIterable(outs)) +): Channel.Channel => writeChunk(Chunk.fromIterable(outs)) /** @internal */ export const writeChunk = ( outs: Chunk.Chunk -): Channel.Channel => writeChunkWriter(0, outs.length, outs) +): Channel.Channel => writeChunkWriter(0, outs.length, outs) /** @internal */ const writeChunkWriter = ( idx: number, len: number, chunk: Chunk.Chunk -): Channel.Channel => { +): Channel.Channel => { return idx === len ? core.unit : pipe( @@ -2339,53 +2280,53 @@ const writeChunkWriter = ( /** @internal */ export const zip = dual< - ( - that: Channel.Channel, + ( + that: Channel.Channel, options?: { readonly concurrent?: boolean | undefined } - ) => ( - self: Channel.Channel + ) => ( + self: Channel.Channel ) => Channel.Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1 | OutErr, - OutElem1 | OutElem, - readonly [OutDone, OutDone1] + InErr & InErr1, + readonly [OutDone, OutDone1], + InDone & InDone1, + Env1 | Env >, - ( - self: Channel.Channel, - that: Channel.Channel, + ( + self: Channel.Channel, + that: Channel.Channel, options?: { readonly concurrent?: boolean | undefined } ) => Channel.Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1 | OutErr, - OutElem1 | OutElem, - readonly [OutDone, OutDone1] + InErr & InErr1, + readonly [OutDone, OutDone1], + InDone & InDone1, + Env1 | Env > >( (args) => core.isChannel(args[1]), - ( - self: Channel.Channel, - that: Channel.Channel, + ( + self: Channel.Channel, + that: Channel.Channel, options?: { readonly concurrent?: boolean | undefined } ): Channel.Channel< - Env | Env1, - InErr & InErr1, + OutElem | OutElem1, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem | OutElem1, - readonly [OutDone, OutDone1] + InErr & InErr1, + readonly [OutDone, OutDone1], + InDone & InDone1, + Env | Env1 > => options?.concurrent ? mergeWith(self, { @@ -2398,53 +2339,53 @@ export const zip = dual< /** @internal */ export const zipLeft = dual< - ( - that: Channel.Channel, + ( + that: Channel.Channel, options?: { readonly concurrent?: boolean | undefined } - ) => ( - self: Channel.Channel + ) => ( + self: Channel.Channel ) => Channel.Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1 | OutErr, - OutElem1 | OutElem, - OutDone + InErr & InErr1, + OutDone, + InDone & InDone1, + Env1 | Env >, - ( - self: Channel.Channel, - that: Channel.Channel, + ( + self: Channel.Channel, + that: Channel.Channel, options?: { readonly concurrent?: boolean | undefined } ) => Channel.Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1 | OutErr, - OutElem1 | OutElem, - OutDone + InErr & InErr1, + OutDone, + InDone & InDone1, + Env1 | Env > >( (args) => core.isChannel(args[1]), - ( - self: Channel.Channel, - that: Channel.Channel, + ( + self: Channel.Channel, + that: Channel.Channel, options?: { readonly concurrent?: boolean | undefined } ): Channel.Channel< - Env | Env1, - InErr & InErr1, + OutElem | OutElem1, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem | OutElem1, - OutDone + InErr & InErr1, + OutDone, + InDone & InDone1, + Env | Env1 > => options?.concurrent ? map(zip(self, that, { concurrent: true }), (tuple) => tuple[0]) : @@ -2453,53 +2394,53 @@ export const zipLeft = dual< /** @internal */ export const zipRight = dual< - ( - that: Channel.Channel, + ( + that: Channel.Channel, options?: { readonly concurrent?: boolean | undefined } - ) => ( - self: Channel.Channel + ) => ( + self: Channel.Channel ) => Channel.Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1 | OutErr, - OutElem1 | OutElem, - OutDone1 + InErr & InErr1, + OutDone1, + InDone & InDone1, + Env1 | Env >, - ( - self: Channel.Channel, - that: Channel.Channel, + ( + self: Channel.Channel, + that: Channel.Channel, options?: { readonly concurrent?: boolean | undefined } ) => Channel.Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1 | OutErr, - OutElem1 | OutElem, - OutDone1 + InErr & InErr1, + OutDone1, + InDone & InDone1, + Env1 | Env > >( (args) => core.isChannel(args[1]), - ( - self: Channel.Channel, - that: Channel.Channel, + ( + self: Channel.Channel, + that: Channel.Channel, options?: { readonly concurrent?: boolean | undefined } ): Channel.Channel< - Env | Env1, - InErr & InErr1, + OutElem | OutElem1, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem | OutElem1, - OutDone1 + InErr & InErr1, + OutDone1, + InDone & InDone1, + Env | Env1 > => options?.concurrent ? map(zip(self, that, { concurrent: true }), (tuple) => tuple[1]) : diff --git a/packages/effect/src/internal/channel/channelExecutor.ts b/packages/effect/src/internal/channel/channelExecutor.ts index 57b1970edf..d10ae3387d 100644 --- a/packages/effect/src/internal/channel/channelExecutor.ts +++ b/packages/effect/src/internal/channel/channelExecutor.ts @@ -22,26 +22,10 @@ import * as Continuation from "./continuation.js" import * as Subexecutor from "./subexecutor.js" import * as upstreamPullRequest from "./upstreamPullRequest.js" -export type ErasedChannel = Channel.Channel< - R, - unknown, - unknown, - unknown, - unknown, - unknown, - unknown -> +export type ErasedChannel = Channel.Channel /** @internal */ -export type ErasedExecutor = ChannelExecutor< - R, - unknown, - unknown, - unknown, - unknown, - unknown, - unknown -> +export type ErasedExecutor = ChannelExecutor /** @internal */ export type ErasedContinuation = Continuation.Continuation< @@ -60,7 +44,15 @@ export type ErasedContinuation = Continuation.Continuation< export type ErasedFinalizer = (exit: Exit.Exit) => Effect.Effect /** @internal */ -export class ChannelExecutor { +export class ChannelExecutor< + out OutElem, + in InElem = unknown, + out OutErr = never, + in InErr = unknown, + out OutDone = void, + in InDone = unknown, + in out Env = never +> { private _activeSubexecutor: Subexecutor.Subexecutor | undefined = undefined private _cancelled: Exit.Exit | undefined = undefined @@ -86,7 +78,7 @@ export class ChannelExecutor | undefined constructor( - initialChannel: Channel.Channel, + initialChannel: Channel.Channel, providedEnv: Context.Context | undefined, executeCloseLastSubstream: (effect: Effect.Effect) => Effect.Effect ) { @@ -184,13 +176,13 @@ export class ChannelExecutor = new ChannelExecutor( this._currentChannel.value() as Channel.Channel< - Env, - unknown, - unknown, + never, unknown, never, + unknown, never, - never + unknown, + Env >, this._providedEnv, (effect) => @@ -278,7 +270,7 @@ export class ChannelExecutor = new ChannelExecutor( - this._currentChannel.left() as Channel.Channel, + this._currentChannel.left() as Channel.Channel, this._providedEnv, (effect) => this._executeCloseLastSubstream(effect) ) @@ -1102,12 +1094,12 @@ export const readUpstream = ( /** @internal */ export const run = ( - self: Channel.Channel + self: Channel.Channel ): Effect.Effect => pipe(runScoped(self), Effect.scoped) /** @internal */ export const runScoped = ( - self: Channel.Channel + self: Channel.Channel ): Effect.Effect => { const run = ( channelDeferred: Deferred.Deferred, @@ -1163,7 +1155,7 @@ export const runScoped = ( /** @internal */ const runScopedInterpret = ( channelState: ChannelState.ChannelState, - exec: ChannelExecutor + exec: ChannelExecutor ): Effect.Effect => { const op = channelState as ChannelState.Primitive switch (op._tag) { diff --git a/packages/effect/src/internal/channel/continuation.ts b/packages/effect/src/internal/channel/continuation.ts index bf0fac5cab..5578ecd143 100644 --- a/packages/effect/src/internal/channel/continuation.ts +++ b/packages/effect/src/internal/channel/continuation.ts @@ -98,13 +98,13 @@ export interface ContinuationK< readonly _tag: OpCodes.OP_CONTINUATION_K onSuccess( o: OutDone - ): Channel.Channel + ): Channel.Channel onHalt( c: Cause.Cause - ): Channel.Channel + ): Channel.Channel onExit( exit: Exit.Exit - ): Channel.Channel + ): Channel.Channel } /** @internal */ @@ -176,15 +176,15 @@ export class ContinuationKImpl< constructor( readonly onSuccess: ( o: OutDone - ) => Channel.Channel, + ) => Channel.Channel, readonly onHalt: ( c: Cause.Cause - ) => Channel.Channel + ) => Channel.Channel ) { } onExit( exit: Exit.Exit - ): Channel.Channel { + ): Channel.Channel { return Exit.isFailure(exit) ? this.onHalt(exit.cause) : this.onSuccess(exit.value) } } diff --git a/packages/effect/src/internal/core-stream.ts b/packages/effect/src/internal/core-stream.ts index b7858fae60..30f076e7c4 100644 --- a/packages/effect/src/internal/core-stream.ts +++ b/packages/effect/src/internal/core-stream.ts @@ -54,7 +54,7 @@ const proto = { } /** @internal */ -type ErasedChannel = Channel.Channel +type ErasedChannel = Channel.Channel /** @internal */ export type Op = @@ -203,13 +203,13 @@ export const isChannel = (u: unknown): u is Channel.Channel< /** @internal */ export const acquireReleaseOut = dual< - ( + ( release: (z: Z, e: Exit.Exit) => Effect.Effect - ) => (self: Effect.Effect) => Channel.Channel, - ( + ) => (self: Effect.Effect) => Channel.Channel, + ( self: Effect.Effect, release: (z: Z, e: Exit.Exit) => Effect.Effect - ) => Channel.Channel + ) => Channel.Channel >(2, (self, release) => { const op = Object.create(proto) op._tag = OpCodes.OP_BRACKET_OUT @@ -220,44 +220,44 @@ export const acquireReleaseOut = dual< /** @internal */ export const catchAllCause = dual< - ( - f: (cause: Cause.Cause) => Channel.Channel - ) => ( - self: Channel.Channel + ( + f: (cause: Cause.Cause) => Channel.Channel + ) => ( + self: Channel.Channel ) => Channel.Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1, - OutElem1 | OutElem, - OutDone1 | OutDone + InErr & InErr1, + OutDone1 | OutDone, + InDone & InDone1, + Env1 | Env >, - ( - self: Channel.Channel, - f: (cause: Cause.Cause) => Channel.Channel + ( + self: Channel.Channel, + f: (cause: Cause.Cause) => Channel.Channel ) => Channel.Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1, - OutElem1 | OutElem, - OutDone1 | OutDone + InErr & InErr1, + OutDone1 | OutDone, + InDone & InDone1, + Env1 | Env > >( 2, - ( - self: Channel.Channel, - f: (cause: Cause.Cause) => Channel.Channel + ( + self: Channel.Channel, + f: (cause: Cause.Cause) => Channel.Channel ): Channel.Channel< - Env | Env1, - InErr & InErr1, + OutElem | OutElem1, InElem & InElem1, - InDone & InDone1, OutErr1, - OutElem | OutElem1, - OutDone | OutDone1 + InErr & InErr1, + OutDone | OutDone1, + InDone & InDone1, + Env | Env1 > => { const op = Object.create(proto) op._tag = OpCodes.OP_FOLD @@ -269,16 +269,8 @@ export const catchAllCause = dual< /** @internal */ export const collectElements = ( - self: Channel.Channel -): Channel.Channel< - Env, - InErr, - InElem, - InDone, - OutErr, - never, - [Chunk.Chunk, OutDone] -> => { + self: Channel.Channel +): Channel.Channel, OutDone], InDone, Env> => { return suspend(() => { const builder: Array = [] return flatMap( @@ -291,7 +283,7 @@ export const collectElements = ( builder: Array -): Channel.Channel => +): Channel.Channel => readWith({ onInput: (outElem) => flatMap( @@ -305,54 +297,54 @@ const collectElementsReader = ( }) /** @internal */ -export const concatAll = ( +export const concatAll = ( channels: Channel.Channel< - Env, - InErr, + Channel.Channel, InElem, - InDone, OutErr, - Channel.Channel, - any + InErr, + any, + InDone, + Env > -): Channel.Channel => concatAllWith(channels, constVoid, constVoid) +): Channel.Channel => concatAllWith(channels, constVoid, constVoid) /** @internal */ export const concatAllWith = < - Env, - InErr, - InElem, - InDone, - OutErr, OutElem, - OutDone, - OutDone2, - OutDone3, - Env2, - InErr2, InElem2, + OutErr2, + InErr2, + OutDone, InDone2, - OutErr2 + Env2, + InElem, + OutErr, + InErr, + OutDone2, + InDone, + Env, + OutDone3 >( channels: Channel.Channel< - Env, - InErr, + Channel.Channel, InElem, - InDone, OutErr, - Channel.Channel, - OutDone2 + InErr, + OutDone2, + InDone, + Env >, f: (o: OutDone, o1: OutDone) => OutDone, g: (o: OutDone, o2: OutDone2) => OutDone3 ): Channel.Channel< - Env | Env2, - InErr & InErr2, + OutElem, InElem & InElem2, - InDone & InDone2, OutErr | OutErr2, - OutElem, - OutDone3 + InErr & InErr2, + OutDone3, + InDone & InDone2, + Env | Env2 > => { const op = Object.create(proto) op._tag = OpCodes.OP_CONCAT_ALL @@ -367,50 +359,50 @@ export const concatAllWith = < /** @internal */ export const concatMapWith = dual< - ( - f: (o: OutElem) => Channel.Channel, + ( + f: (o: OutElem) => Channel.Channel, g: (o: OutDone, o1: OutDone) => OutDone, h: (o: OutDone, o2: OutDone2) => OutDone3 ) => ( - self: Channel.Channel + self: Channel.Channel ) => Channel.Channel< - Env2 | Env, - InErr & InErr2, + OutElem2, InElem & InElem2, - InDone & InDone2, OutErr2 | OutErr, - OutElem2, - OutDone3 + InErr & InErr2, + OutDone3, + InDone & InDone2, + Env2 | Env >, < - Env, - InErr, + OutElem, InElem, - InDone, OutErr, - OutElem, - OutElem2, - OutDone, + InErr, OutDone2, - OutDone3, - Env2, - InErr2, + InDone, + Env, + OutElem2, InElem2, + OutErr2, + InErr2, + OutDone, InDone2, - OutErr2 + Env2, + OutDone3 >( - self: Channel.Channel, - f: (o: OutElem) => Channel.Channel, + self: Channel.Channel, + f: (o: OutElem) => Channel.Channel, g: (o: OutDone, o1: OutDone) => OutDone, h: (o: OutDone, o2: OutDone2) => OutDone3 ) => Channel.Channel< - Env2 | Env, - InErr & InErr2, + OutElem2, InElem & InElem2, - InDone & InDone2, OutErr2 | OutErr, - OutElem2, - OutDone3 + InErr & InErr2, + OutDone3, + InDone & InDone2, + Env2 | Env > >(4, < Env, @@ -429,20 +421,20 @@ export const concatMapWith = dual< InDone2, OutErr2 >( - self: Channel.Channel, + self: Channel.Channel, f: ( o: OutElem - ) => Channel.Channel, + ) => Channel.Channel, g: (o: OutDone, o1: OutDone) => OutDone, h: (o: OutDone, o2: OutDone2) => OutDone3 ): Channel.Channel< - Env | Env2, - InErr & InErr2, + OutElem2, InElem & InElem2, - InDone & InDone2, OutErr | OutErr2, - OutElem2, - OutDone3 + InErr & InErr2, + OutDone3, + InDone & InDone2, + Env | Env2 > => { const op = Object.create(proto) op._tag = OpCodes.OP_CONCAT_ALL @@ -457,8 +449,8 @@ export const concatMapWith = dual< /** @internal */ export const concatMapWithCustom = dual< - ( - f: (o: OutElem) => Channel.Channel, + ( + f: (o: OutElem) => Channel.Channel, g: (o: OutDone, o1: OutDone) => OutDone, h: (o: OutDone, o2: OutDone2) => OutDone3, onPull: ( @@ -466,35 +458,35 @@ export const concatMapWithCustom = dual< ) => UpstreamPullStrategy.UpstreamPullStrategy, onEmit: (elem: OutElem2) => ChildExecutorDecision.ChildExecutorDecision ) => ( - self: Channel.Channel + self: Channel.Channel ) => Channel.Channel< - Env2 | Env, - InErr & InErr2, + OutElem2, InElem & InElem2, - InDone & InDone2, OutErr2 | OutErr, - OutElem2, - OutDone3 + InErr & InErr2, + OutDone3, + InDone & InDone2, + Env2 | Env >, < - Env, - InErr, + OutElem, InElem, - InDone, OutErr, - OutElem, - OutElem2, - OutDone, + InErr, OutDone2, - OutDone3, - Env2, - InErr2, + InDone, + Env, + OutElem2, InElem2, + OutErr2, + InErr2, + OutDone, InDone2, - OutErr2 + Env2, + OutDone3 >( - self: Channel.Channel, - f: (o: OutElem) => Channel.Channel, + self: Channel.Channel, + f: (o: OutElem) => Channel.Channel, g: (o: OutDone, o1: OutDone) => OutDone, h: (o: OutDone, o2: OutDone2) => OutDone3, onPull: ( @@ -502,13 +494,13 @@ export const concatMapWithCustom = dual< ) => UpstreamPullStrategy.UpstreamPullStrategy, onEmit: (elem: OutElem2) => ChildExecutorDecision.ChildExecutorDecision ) => Channel.Channel< - Env2 | Env, - InErr & InErr2, + OutElem2, InElem & InElem2, - InDone & InDone2, OutErr2 | OutErr, - OutElem2, - OutDone3 + InErr & InErr2, + OutDone3, + InDone & InDone2, + Env2 | Env > >(6, < Env, @@ -527,10 +519,10 @@ export const concatMapWithCustom = dual< InDone2, OutErr2 >( - self: Channel.Channel, + self: Channel.Channel, f: ( o: OutElem - ) => Channel.Channel, + ) => Channel.Channel, g: (o: OutDone, o1: OutDone) => OutDone, h: (o: OutDone, o2: OutDone2) => OutDone3, onPull: ( @@ -538,13 +530,13 @@ export const concatMapWithCustom = dual< ) => UpstreamPullStrategy.UpstreamPullStrategy, onEmit: (elem: OutElem2) => ChildExecutorDecision.ChildExecutorDecision ): Channel.Channel< - Env | Env2, - InErr & InErr2, + OutElem2, InElem & InElem2, - InDone & InDone2, OutErr | OutErr2, - OutElem2, - OutDone3 + InErr & InErr2, + OutDone3, + InDone & InDone2, + Env | Env2 > => { const op = Object.create(proto) op._tag = OpCodes.OP_CONCAT_ALL @@ -561,19 +553,19 @@ export const concatMapWithCustom = dual< export const embedInput = dual< ( input: SingleProducerAsyncInput.AsyncInputProducer - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, input: SingleProducerAsyncInput.AsyncInputProducer - ) => Channel.Channel + ) => Channel.Channel >( 2, - ( - self: Channel.Channel, + ( + self: Channel.Channel, input: SingleProducerAsyncInput.AsyncInputProducer - ): Channel.Channel => { + ): Channel.Channel => { const op = Object.create(proto) op._tag = OpCodes.OP_BRIDGE op.input = input @@ -584,21 +576,21 @@ export const embedInput = dual< /** @internal */ export const ensuringWith = dual< - ( + ( finalizer: (e: Exit.Exit) => Effect.Effect - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, finalizer: (e: Exit.Exit) => Effect.Effect - ) => Channel.Channel + ) => Channel.Channel >( 2, - ( - self: Channel.Channel, + ( + self: Channel.Channel, finalizer: (e: Exit.Exit) => Effect.Effect - ): Channel.Channel => { + ): Channel.Channel => { const op = Object.create(proto) op._tag = OpCodes.OP_ENSURING op.channel = self @@ -608,23 +600,23 @@ export const ensuringWith = dual< ) /** @internal */ -export const fail = (error: E): Channel.Channel => +export const fail = (error: E): Channel.Channel => failCause(Cause.fail(error)) /** @internal */ export const failSync = ( evaluate: LazyArg -): Channel.Channel => failCauseSync(() => Cause.fail(evaluate())) +): Channel.Channel => failCauseSync(() => Cause.fail(evaluate())) /** @internal */ export const failCause = ( cause: Cause.Cause -): Channel.Channel => failCauseSync(() => cause) +): Channel.Channel => failCauseSync(() => cause) /** @internal */ export const failCauseSync = ( evaluate: LazyArg> -): Channel.Channel => { +): Channel.Channel => { const op = Object.create(proto) op._tag = OpCodes.OP_FAIL op.error = evaluate @@ -633,44 +625,44 @@ export const failCauseSync = ( /** @internal */ export const flatMap = dual< - ( - f: (d: OutDone) => Channel.Channel - ) => ( - self: Channel.Channel + ( + f: (d: OutDone) => Channel.Channel + ) => ( + self: Channel.Channel ) => Channel.Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1 | OutErr, - OutElem1 | OutElem, - OutDone2 + InErr & InErr1, + OutDone2, + InDone & InDone1, + Env1 | Env >, - ( - self: Channel.Channel, - f: (d: OutDone) => Channel.Channel + ( + self: Channel.Channel, + f: (d: OutDone) => Channel.Channel ) => Channel.Channel< - Env1 | Env, - InErr & InErr1, + OutElem1 | OutElem, InElem & InElem1, - InDone & InDone1, OutErr1 | OutErr, - OutElem1 | OutElem, - OutDone2 + InErr & InErr1, + OutDone2, + InDone & InDone1, + Env1 | Env > >( 2, - ( - self: Channel.Channel, - f: (d: OutDone) => Channel.Channel + ( + self: Channel.Channel, + f: (d: OutDone) => Channel.Channel ): Channel.Channel< - Env | Env1, - InErr & InErr1, + OutElem | OutElem1, InElem & InElem1, - InDone & InDone1, OutErr | OutErr1, - OutElem | OutElem1, - OutDone2 + InErr & InErr1, + OutDone2, + InDone & InDone1, + Env | Env1 > => { const op = Object.create(proto) op._tag = OpCodes.OP_FOLD @@ -683,119 +675,119 @@ export const flatMap = dual< /** @internal */ export const foldCauseChannel = dual< < - Env1, - Env2, - InErr1, - InErr2, - InElem1, - InElem2, - InDone1, - InDone2, OutErr, - OutErr2, - OutErr3, OutElem1, - OutElem2, - OutDone, + InElem1, + OutErr2, + InErr1, OutDone2, - OutDone3 + InDone1, + Env1, + OutDone, + OutElem2, + InElem2, + OutErr3, + InErr2, + OutDone3, + InDone2, + Env2 >( options: { readonly onFailure: ( c: Cause.Cause - ) => Channel.Channel - readonly onSuccess: (o: OutDone) => Channel.Channel + ) => Channel.Channel + readonly onSuccess: (o: OutDone) => Channel.Channel } ) => ( - self: Channel.Channel + self: Channel.Channel ) => Channel.Channel< - Env1 | Env2 | Env, - InErr & InErr1 & InErr2, + OutElem1 | OutElem2 | OutElem, InElem & InElem1 & InElem2, - InDone & InDone1 & InDone2, OutErr2 | OutErr3, - OutElem1 | OutElem2 | OutElem, - OutDone2 | OutDone3 + InErr & InErr1 & InErr2, + OutDone2 | OutDone3, + InDone & InDone1 & InDone2, + Env1 | Env2 | Env >, < - Env, - InErr, + OutElem, InElem, + OutErr, + InErr, + OutDone, InDone, - OutElem, - Env1, - Env2, - InErr1, - InErr2, + Env, + OutElem1, InElem1, - InElem2, - InDone1, - InDone2, - OutErr, OutErr2, - OutErr3, - OutElem1, - OutElem2, - OutDone, + InErr1, OutDone2, - OutDone3 + InDone1, + Env1, + OutElem2, + InElem2, + OutErr3, + InErr2, + OutDone3, + InDone2, + Env2 >( - self: Channel.Channel, + self: Channel.Channel, options: { readonly onFailure: ( c: Cause.Cause - ) => Channel.Channel - readonly onSuccess: (o: OutDone) => Channel.Channel + ) => Channel.Channel + readonly onSuccess: (o: OutDone) => Channel.Channel } ) => Channel.Channel< - Env1 | Env2 | Env, - InErr & InErr1 & InErr2, + OutElem1 | OutElem2 | OutElem, InElem & InElem1 & InElem2, - InDone & InDone1 & InDone2, OutErr2 | OutErr3, - OutElem1 | OutElem2 | OutElem, - OutDone2 | OutDone3 + InErr & InErr1 & InErr2, + OutDone2 | OutDone3, + InDone & InDone1 & InDone2, + Env1 | Env2 | Env > >( 2, < - Env, - InErr, + OutElem, InElem, + OutErr, + InErr, + OutDone, InDone, - OutElem, - Env1, - Env2, - InErr1, - InErr2, + Env, + OutElem1, InElem1, - InElem2, - InDone1, - InDone2, - OutErr, OutErr2, - OutErr3, - OutElem1, - OutElem2, - OutDone, + InErr1, OutDone2, - OutDone3 + InDone1, + Env1, + OutElem2, + InElem2, + OutErr3, + InErr2, + OutDone3, + InDone2, + Env2 >( - self: Channel.Channel, + self: Channel.Channel, options: { readonly onFailure: ( c: Cause.Cause - ) => Channel.Channel - readonly onSuccess: (o: OutDone) => Channel.Channel + ) => Channel.Channel + readonly onSuccess: (o: OutDone) => Channel.Channel } ): Channel.Channel< - Env | Env1 | Env2, - InErr & InErr1 & InErr2, + OutElem | OutElem1 | OutElem2, InElem & InElem1 & InElem2, - InDone & InDone1 & InDone2, OutErr2 | OutErr3, - OutElem | OutElem1 | OutElem2, - OutDone2 | OutDone3 + InErr & InErr1 & InErr2, + OutDone2 | OutDone3, + InDone & InDone1 & InDone2, + Env | Env1 | Env2 > => { const op = Object.create(proto) op._tag = OpCodes.OP_FOLD @@ -808,7 +800,7 @@ export const foldCauseChannel = dual< /** @internal */ export const fromEffect = ( effect: Effect.Effect -): Channel.Channel => { +): Channel.Channel => { const op = Object.create(proto) op._tag = OpCodes.OP_FROM_EFFECT op.effect = () => effect @@ -817,21 +809,21 @@ export const fromEffect = ( /** @internal */ export const pipeTo = dual< - ( - that: Channel.Channel - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, - that: Channel.Channel - ) => Channel.Channel + ( + that: Channel.Channel + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, + that: Channel.Channel + ) => Channel.Channel >( 2, - ( - self: Channel.Channel, - that: Channel.Channel - ): Channel.Channel => { + ( + self: Channel.Channel, + that: Channel.Channel + ): Channel.Channel => { const op = Object.create(proto) op._tag = OpCodes.OP_PIPE_TO op.left = () => self @@ -844,19 +836,19 @@ export const pipeTo = dual< export const provideContext = dual< ( env: Context.Context - ) => ( - self: Channel.Channel - ) => Channel.Channel, - ( - self: Channel.Channel, + ) => ( + self: Channel.Channel + ) => Channel.Channel, + ( + self: Channel.Channel, env: Context.Context - ) => Channel.Channel + ) => Channel.Channel >( 2, - ( - self: Channel.Channel, + ( + self: Channel.Channel, env: Context.Context - ): Channel.Channel => { + ): Channel.Channel => { const op = Object.create(proto) op._tag = OpCodes.OP_PROVIDE op.context = () => env @@ -866,9 +858,9 @@ export const provideContext = dual< ) /** @internal */ -export const readOrFail = ( +export const readOrFail = ( error: E -): Channel.Channel => { +): Channel.Channel => { const op = Object.create(proto) op._tag = OpCodes.OP_READ op.more = succeed @@ -878,35 +870,35 @@ export const readOrFail = ( /** @internal */ export const readWith = < - Env, - InErr, InElem, - InDone, - OutErr, OutElem, + OutErr, + InErr, OutDone, - Env2, - OutErr2, + InDone, + Env, OutElem2, + OutErr2, OutDone2, - Env3, - OutErr3, + Env2, OutElem3, - OutDone3 + OutErr3, + OutDone3, + Env3 >( options: { - readonly onInput: (input: InElem) => Channel.Channel - readonly onFailure: (error: InErr) => Channel.Channel - readonly onDone: (done: InDone) => Channel.Channel + readonly onInput: (input: InElem) => Channel.Channel + readonly onFailure: (error: InErr) => Channel.Channel + readonly onDone: (done: InDone) => Channel.Channel } ): Channel.Channel< - Env | Env2 | Env3, - InErr, + OutElem | OutElem2 | OutElem3, InElem, - InDone, OutErr | OutErr2 | OutErr3, - OutElem | OutElem2 | OutElem3, - OutDone | OutDone2 | OutDone3 + InErr, + OutDone | OutDone2 | OutDone3, + InDone, + Env | Env2 | Env3 > => readWithCause({ onInput: options.onInput, @@ -916,37 +908,37 @@ export const readWith = < /** @internal */ export const readWithCause = < - Env, - InErr, InElem, - InDone, - OutErr, OutElem, + OutErr, + InErr, OutDone, - Env2, - OutErr2, + InDone, + Env, OutElem2, + OutErr2, OutDone2, - Env3, - OutErr3, + Env2, OutElem3, - OutDone3 + OutErr3, + OutDone3, + Env3 >( options: { - readonly onInput: (input: InElem) => Channel.Channel + readonly onInput: (input: InElem) => Channel.Channel readonly onFailure: ( cause: Cause.Cause - ) => Channel.Channel - readonly onDone: (done: InDone) => Channel.Channel + ) => Channel.Channel + readonly onDone: (done: InDone) => Channel.Channel } ): Channel.Channel< - Env | Env2 | Env3, - InErr, + OutElem | OutElem2 | OutElem3, InElem, - InDone, OutErr | OutErr2 | OutErr3, - OutElem | OutElem2 | OutElem3, - OutDone | OutDone2 | OutDone3 + InErr, + OutDone | OutDone2 | OutDone3, + InDone, + Env | Env2 | Env3 > => { const op = Object.create(proto) op._tag = OpCodes.OP_READ @@ -958,12 +950,12 @@ export const readWithCause = < /** @internal */ export const succeed = ( value: A -): Channel.Channel => sync(() => value) +): Channel.Channel => sync(() => value) /** @internal */ export const succeedNow = ( result: OutDone -): Channel.Channel => { +): Channel.Channel => { const op = Object.create(proto) op._tag = OpCodes.OP_SUCCEED_NOW op.terminal = result @@ -971,9 +963,9 @@ export const succeedNow = ( } /** @internal */ -export const suspend = ( - evaluate: LazyArg> -): Channel.Channel => { +export const suspend = ( + evaluate: LazyArg> +): Channel.Channel => { const op = Object.create(proto) op._tag = OpCodes.OP_SUSPEND op.channel = evaluate @@ -982,7 +974,7 @@ export const suspend = ( export const sync = ( evaluate: LazyArg -): Channel.Channel => { +): Channel.Channel => { const op = Object.create(proto) op._tag = OpCodes.OP_SUCCEED op.evaluate = evaluate @@ -990,12 +982,12 @@ export const sync = ( } /** @internal */ -export const unit: Channel.Channel = succeedNow(void 0) +export const unit: Channel.Channel = succeedNow(void 0) /** @internal */ export const write = ( out: OutElem -): Channel.Channel => { +): Channel.Channel => { const op = Object.create(proto) op._tag = OpCodes.OP_EMIT op.out = out diff --git a/packages/effect/src/internal/groupBy.ts b/packages/effect/src/internal/groupBy.ts index a45b99e18d..c5672b4ea4 100644 --- a/packages/effect/src/internal/groupBy.ts +++ b/packages/effect/src/internal/groupBy.ts @@ -419,7 +419,7 @@ export const groupByKey = dual< const loop = ( map: Map>>, outerQueue: Queue.Queue>], E>> - ): Channel.Channel, unknown, E, never, unknown> => + ): Channel.Channel, E, E, unknown, unknown, R> => core.readWithCause({ onInput: (input: Chunk.Chunk) => core.flatMap( diff --git a/packages/effect/src/internal/sink.ts b/packages/effect/src/internal/sink.ts index dc82711df7..4abb7067a0 100644 --- a/packages/effect/src/internal/sink.ts +++ b/packages/effect/src/internal/sink.ts @@ -45,7 +45,7 @@ const sinkVariance = { export class SinkImpl implements Sink.Sink { readonly [SinkTypeId] = sinkVariance constructor( - readonly channel: Channel.Channel, unknown, E, Chunk.Chunk, Z> + readonly channel: Channel.Channel, Chunk.Chunk, E, never, Z, unknown, R> ) { } pipe() { @@ -77,7 +77,7 @@ export const collectAll = (): Sink.Sink( acc: Chunk.Chunk -): Channel.Channel, unknown, never, never, Chunk.Chunk> => +): Channel.Channel, never, never, Chunk.Chunk, unknown> => core.readWithCause({ onInput: (chunk: Chunk.Chunk) => collectAllLoop(pipe(acc, Chunk.appendAll(chunk))), onFailure: core.failCause, @@ -92,7 +92,7 @@ export const collectAllN = (n: number): Sink.Sink( n: number, acc: Chunk.Chunk -): Channel.Channel, unknown, never, Chunk.Chunk, Chunk.Chunk> => +): Channel.Channel, Chunk.Chunk, never, never, Chunk.Chunk, unknown> => core.readWithCause({ onInput: (chunk: Chunk.Chunk) => { const [collected, leftovers] = Chunk.splitAt(chunk, n) @@ -209,7 +209,7 @@ export const collectAllWhile: { const collectAllWhileReader = ( predicate: Predicate, done: Chunk.Chunk -): Channel.Channel, unknown, never, Chunk.Chunk, Chunk.Chunk> => +): Channel.Channel, Chunk.Chunk, never, never, Chunk.Chunk, unknown> => core.readWith({ onInput: (input: Chunk.Chunk) => { const [collected, leftovers] = pipe(Chunk.toReadonlyArray(input), ReadonlyArray.span(predicate)) @@ -237,7 +237,7 @@ export const collectAllWhileEffect = ( const collectAllWhileEffectReader = ( predicate: (input: In) => Effect.Effect, done: Chunk.Chunk -): Channel.Channel, unknown, E, Chunk.Chunk, Chunk.Chunk> => +): Channel.Channel, Chunk.Chunk, E, never, Chunk.Chunk, unknown, R> => core.readWith({ onInput: (input: Chunk.Chunk) => pipe( @@ -288,8 +288,8 @@ export const collectAllWhileWith = dual< const newChannel = pipe( core.fromEffect(refs), core.flatMap(([leftoversRef, upstreamDoneRef]) => { - const upstreamMarker: Channel.Channel, unknown, never, Chunk.Chunk, unknown> = - core.readWith({ + const upstreamMarker: Channel.Channel, Chunk.Chunk, never, never, unknown, unknown> = core + .readWith({ onInput: (input) => pipe(core.write(input), core.flatMap(() => upstreamMarker)), onFailure: core.fail, onDone: (done) => pipe(core.fromEffect(Ref.set(upstreamDoneRef, true)), channel.as(done)) @@ -315,7 +315,7 @@ const collectAllWhileWithLoop = ( currentResult: S, p: Predicate, f: (s: S, z: Z) => S -): Channel.Channel, unknown, E, Chunk.Chunk, S> => { +): Channel.Channel, Chunk.Chunk, E, never, S, unknown, R> => { return pipe( toChannel(self), channel.doneCollect, @@ -400,7 +400,7 @@ export const mapInputChunks = dual< self: Sink.Sink, f: (chunk: Chunk.Chunk) => Chunk.Chunk ): Sink.Sink => { - const loop: Channel.Channel, unknown, never, Chunk.Chunk, unknown> = core.readWith({ + const loop: Channel.Channel, Chunk.Chunk, never, never, unknown, unknown, R> = core.readWith({ onInput: (chunk) => pipe(core.write(f(chunk)), core.flatMap(() => loop)), onFailure: core.fail, onDone: core.succeed @@ -424,7 +424,7 @@ export const mapInputChunksEffect = dual< self: Sink.Sink, f: (chunk: Chunk.Chunk) => Effect.Effect, E2, R2> ): Sink.Sink => { - const loop: Channel.Channel, unknown, E2, Chunk.Chunk, unknown> = core + const loop: Channel.Channel, Chunk.Chunk, E2, never, unknown, unknown, R | R2> = core .readWith({ onInput: (chunk) => pipe(core.fromEffect(f(chunk)), core.flatMap(core.write), core.flatMap(() => loop)), onFailure: core.fail, @@ -560,7 +560,7 @@ export const dimapChunksEffect = dual< /** @internal */ export const drain: Sink.Sink = new SinkImpl( - channel.drain(channel.identityChannel()) + channel.drain(channel.identityChannel()) ) /** @internal */ @@ -570,7 +570,7 @@ export const drop = (n: number): Sink.Sink => /** @internal */ const dropLoop = ( n: number -): Channel.Channel, unknown, never, Chunk.Chunk, unknown> => +): Channel.Channel, Chunk.Chunk, never, never, unknown, unknown> => core.readWith({ onInput: (input: Chunk.Chunk) => { const dropped = pipe(input, Chunk.drop(n)) @@ -581,7 +581,7 @@ const dropLoop = ( } return pipe( core.write(dropped), - channel.zipRight(channel.identityChannel, unknown>()) + channel.zipRight(channel.identityChannel, never, unknown>()) ) }, onFailure: core.fail, @@ -602,7 +602,7 @@ export const dropUntilEffect = ( /** @internal */ const dropUntilEffectReader = ( predicate: (input: In) => Effect.Effect -): Channel.Channel, unknown, E, Chunk.Chunk, unknown> => +): Channel.Channel, Chunk.Chunk, E, E, unknown, unknown, R> => core.readWith({ onInput: (input: Chunk.Chunk) => pipe( @@ -614,7 +614,7 @@ const dropUntilEffectReader = ( dropUntilEffectReader(predicate) : pipe( core.write(Chunk.unsafeFromArray(leftover)), - channel.zipRight(channel.identityChannel, unknown>()) + channel.zipRight(channel.identityChannel, E, unknown>()) ) }), channel.unwrap @@ -630,14 +630,14 @@ export const dropWhile = (predicate: Predicate): Sink.Sink( predicate: Predicate -): Channel.Channel, unknown, never, Chunk.Chunk, unknown> => +): Channel.Channel, Chunk.Chunk, never, never, unknown, unknown> => core.readWith({ onInput: (input: Chunk.Chunk) => { const out = pipe(input, Chunk.dropWhile(predicate)) if (Chunk.isEmpty(out)) { return dropWhileReader(predicate) } - return pipe(core.write(out), channel.zipRight(channel.identityChannel, unknown>())) + return pipe(core.write(out), channel.zipRight(channel.identityChannel, never, unknown>())) }, onFailure: core.fail, onDone: core.succeedNow @@ -651,7 +651,7 @@ export const dropWhileEffect = ( /** @internal */ const dropWhileEffectReader = ( predicate: (input: In) => Effect.Effect -): Channel.Channel, unknown, E, Chunk.Chunk, unknown> => +): Channel.Channel, Chunk.Chunk, E, E, unknown, unknown, R> => core.readWith({ onInput: (input: Chunk.Chunk) => pipe( @@ -663,7 +663,7 @@ const dropWhileEffectReader = ( dropWhileEffectReader(predicate) : pipe( core.write(Chunk.unsafeFromArray(leftover)), - channel.zipRight(channel.identityChannel, unknown>()) + channel.zipRight(channel.identityChannel, E, unknown>()) ) }), channel.unwrap @@ -797,13 +797,13 @@ export const findEffect = dual< Effect.zip(Ref.make(false)) )), core.flatMap(([leftoversRef, upstreamDoneRef]) => { - const upstreamMarker: Channel.Channel, unknown, never, Chunk.Chunk, unknown> = - core.readWith({ + const upstreamMarker: Channel.Channel, Chunk.Chunk, never, never, unknown, unknown> = core + .readWith({ onInput: (input) => pipe(core.write(input), core.flatMap(() => upstreamMarker)), onFailure: core.fail, onDone: (done) => pipe(core.fromEffect(Ref.set(upstreamDoneRef, true)), channel.as(done)) }) - const loop: Channel.Channel, unknown, E | E2, Chunk.Chunk, Option.Option> = + const loop: Channel.Channel, Chunk.Chunk, E | E2, never, Option.Option, unknown, R | R2> = channel.foldChannel(core.collectElements(toChannel(self)), { onFailure: core.fail, onSuccess: ([leftovers, doneValue]) => @@ -849,7 +849,7 @@ const foldReader = ( s: S, contFn: Predicate, f: (z: S, input: In) => S -): Channel.Channel, unknown, never, Chunk.Chunk, S> => { +): Channel.Channel, Chunk.Chunk, never, never, S, unknown> => { if (!contFn(s)) { return core.succeedNow(s) } @@ -910,13 +910,13 @@ export const foldSink = dual< } ): Sink.Sink => { const newChannel: Channel.Channel< - R | R1 | R2, - never, + Chunk.Chunk, Chunk.Chunk, - unknown, E1 | E2, - Chunk.Chunk, - Z1 | Z2 + never, + Z1 | Z2, + unknown, + R | R1 | R2 > = pipe( toChannel(self), core.collectElements, @@ -937,7 +937,7 @@ export const foldSink = dual< // L <: In1 and therefore Chunk[L] can be safely cast to Chunk[In1]. core.flatMap((chunk) => channel.writeChunk(chunk as Chunk.Chunk>)) ) - const passthrough = channel.identityChannel, unknown>() + const passthrough = channel.identityChannel, never, unknown>() const continuationSink = pipe( refReader, channel.zipRight(passthrough), @@ -972,7 +972,7 @@ const foldChunksReader = ( s: S, contFn: Predicate, f: (s: S, chunk: Chunk.Chunk) => S -): Channel.Channel, unknown, never, never, S> => { +): Channel.Channel, never, never, S, unknown> => { if (!contFn(s)) { return core.succeedNow(s) } @@ -995,7 +995,7 @@ const foldChunksEffectReader = ( s: S, contFn: Predicate, f: (s: S, chunk: Chunk.Chunk) => Effect.Effect -): Channel.Channel, unknown, E, never, S> => { +): Channel.Channel, E, E, S, unknown, R> => { if (!contFn(s)) { return core.succeedNow(s) } @@ -1022,7 +1022,7 @@ const foldEffectReader = ( s: S, contFn: Predicate, f: (s: S, input: In) => Effect.Effect -): Channel.Channel, unknown, E, Chunk.Chunk, S> => { +): Channel.Channel, Chunk.Chunk, E, E, S, unknown, R> => { if (!contFn(s)) { return core.succeedNow(s) } @@ -1171,7 +1171,7 @@ const foldWeightedDecomposeLoop = ( costFn: (s: S, input: In) => number, decompose: (input: In) => Chunk.Chunk, f: (s: S, input: In) => S -): Channel.Channel, unknown, never, Chunk.Chunk, S> => +): Channel.Channel, Chunk.Chunk, never, never, S, unknown> => core.readWith({ onInput: (input: Chunk.Chunk) => { const [nextS, nextCost, nextDirty, leftovers] = foldWeightedDecomposeFold( @@ -1282,7 +1282,7 @@ const foldWeightedDecomposeEffectLoop = ( f: (s: S, input: In) => Effect.Effect, cost: number, dirty: boolean -): Channel.Channel, unknown, E | E2 | E3, Chunk.Chunk, S> => +): Channel.Channel, Chunk.Chunk, E | E2 | E3, E | E2 | E3, S, unknown, R | R2 | R3> => core.readWith({ onInput: (input: Chunk.Chunk) => pipe( @@ -1375,7 +1375,7 @@ export const flatMap = dual< /** @internal */ export const forEach = (f: (input: In) => Effect.Effect<_, E, R>): Sink.Sink => { - const process: Channel.Channel, unknown, E, never, void> = core.readWithCause({ + const process: Channel.Channel, E, E, void, unknown, R> = core.readWithCause({ onInput: (input: Chunk.Chunk) => pipe(core.fromEffect(Effect.forEach(input, (v) => f(v), { discard: true })), core.flatMap(() => process)), onFailure: core.failCause, @@ -1388,7 +1388,7 @@ export const forEach = (f: (input: In) => Effect.Effect<_, E, R>): export const forEachChunk = ( f: (input: Chunk.Chunk) => Effect.Effect<_, E, R> ): Sink.Sink => { - const process: Channel.Channel, unknown, E, never, void> = core.readWithCause({ + const process: Channel.Channel, E, E, void, unknown, R> = core.readWithCause({ onInput: (input: Chunk.Chunk) => pipe(core.fromEffect(f(input)), core.flatMap(() => process)), onFailure: core.failCause, onDone: () => core.unit @@ -1400,7 +1400,7 @@ export const forEachChunk = ( export const forEachWhile = ( f: (input: In) => Effect.Effect ): Sink.Sink => { - const process: Channel.Channel, unknown, E, Chunk.Chunk, void> = core.readWithCause({ + const process: Channel.Channel, Chunk.Chunk, E, E, void, unknown, R> = core.readWithCause({ onInput: (input: Chunk.Chunk) => forEachWhileReader(f, input, 0, input.length, process), onFailure: core.failCause, onDone: () => core.unit @@ -1414,8 +1414,8 @@ const forEachWhileReader = ( input: Chunk.Chunk, index: number, length: number, - cont: Channel.Channel, unknown, E, Chunk.Chunk, void> -): Channel.Channel, unknown, E, Chunk.Chunk, void> => { + cont: Channel.Channel, Chunk.Chunk, E, E, void, unknown, R> +): Channel.Channel, Chunk.Chunk, E, E, void, unknown, R> => { if (index === length) { return cont } @@ -1434,7 +1434,7 @@ const forEachWhileReader = ( export const forEachChunkWhile = ( f: (input: Chunk.Chunk) => Effect.Effect ): Sink.Sink => { - const reader: Channel.Channel, unknown, E, never, void> = core.readWith({ + const reader: Channel.Channel, E, E, void, unknown, R> = core.readWith({ onInput: (input: Chunk.Chunk) => pipe( core.fromEffect(f(input)), @@ -1448,7 +1448,7 @@ export const forEachChunkWhile = ( /** @internal */ export const fromChannel = ( - channel: Channel.Channel, unknown, E, Chunk.Chunk, Z> + channel: Channel.Channel, Chunk.Chunk, E, never, Z, unknown, R> ): Sink.Sink => new SinkImpl(channel) /** @internal */ @@ -1477,7 +1477,7 @@ const fromPushPull = ( push: ( option: Option.Option> ) => Effect.Effect, Chunk.Chunk], R> -): Channel.Channel, unknown, E, Chunk.Chunk, Z> => +): Channel.Channel, Chunk.Chunk, E, never, Z, unknown, R> => core.readWith({ onInput: (input: Chunk.Chunk) => channel.foldChannel(core.fromEffect(push(Option.some(input))), { @@ -1721,13 +1721,13 @@ export const raceWith = dual< }) ) const racedChannel: Channel.Channel< - R | R2, - never, + Chunk.Chunk, Chunk.Chunk, - unknown, E | E2, - Chunk.Chunk, - Z3 | Z4 + never, + Z3 | Z4, + unknown, + R | R2 > = channel.mergeWith(reader, { other: writer, onSelfDone: (_) => mergeDecision.Await((exit) => Effect.suspend(() => exit)), @@ -1850,7 +1850,7 @@ const splitWhereSplitter = ( written: boolean, leftovers: Ref.Ref>, f: Predicate -): Channel.Channel, unknown, E, Chunk.Chunk, unknown> => +): Channel.Channel, Chunk.Chunk, E, never, unknown, unknown> => core.readWithCause({ onInput: (input) => { if (Chunk.isEmpty(input)) { @@ -1967,7 +1967,7 @@ export const take = (n: number): Sink.Sink( self: Sink.Sink -): Channel.Channel, unknown, E, Chunk.Chunk, Z> => +): Channel.Channel, Chunk.Chunk, E, never, Z, unknown, R> => Effect.isEffect(self) ? toChannel(fromEffect(self as Effect.Effect)) : (self as SinkImpl).channel @@ -2128,8 +2128,8 @@ export const zipWith = dual< // Circular with Channel /** @internal */ -export const channelToSink = ( - self: Channel.Channel, unknown, OutErr, Chunk.Chunk, OutDone> +export const channelToSink = ( + self: Channel.Channel, Chunk.Chunk, OutErr, InErr, OutDone, unknown, Env> ): Sink.Sink => new SinkImpl(self) // Constants diff --git a/packages/effect/src/internal/stream.ts b/packages/effect/src/internal/stream.ts index 6ec100a290..34144e2900 100644 --- a/packages/effect/src/internal/stream.ts +++ b/packages/effect/src/internal/stream.ts @@ -69,7 +69,7 @@ const streamVariance = { export class StreamImpl implements Stream.Stream { readonly [StreamTypeId] = streamVariance constructor( - readonly channel: Channel.Channel, unknown> + readonly channel: Channel.Channel, unknown, E, unknown, unknown, unknown, R> ) { } @@ -93,7 +93,7 @@ export const accumulate = (self: Stream.Stream): Stream.Stream export const accumulateChunks = (self: Stream.Stream): Stream.Stream => { const accumulator = ( s: Chunk.Chunk - ): Channel.Channel, unknown, E, Chunk.Chunk, void> => + ): Channel.Channel, Chunk.Chunk, E, E, void, unknown> => core.readWith({ onInput: (input: Chunk.Chunk) => { const next = Chunk.appendAll(s, input) @@ -188,7 +188,7 @@ export const aggregateWithinEither = dual< return pipe( fromEffect(layer), flatMap(([handoff, sinkEndReason, sinkLeftovers, scheduleDriver, consumed, endAfterEmit]) => { - const handoffProducer: Channel.Channel, unknown, never, never, unknown> = core + const handoffProducer: Channel.Channel, never, E | E2, unknown, unknown> = core .readWithCause({ onInput: (input: Chunk.Chunk) => core.flatMap( @@ -214,78 +214,77 @@ export const aggregateWithinEither = dual< ) ) }) - const handoffConsumer: Channel.Channel, void> = - pipe( - Ref.getAndSet(sinkLeftovers, Chunk.empty()), - Effect.flatMap((leftovers) => { - if (Chunk.isNonEmpty(leftovers)) { - return pipe( - Ref.set(consumed, true), - Effect.zipRight(Effect.succeed(pipe( - core.write(leftovers), - core.flatMap(() => handoffConsumer) - ))) - ) - } + const handoffConsumer: Channel.Channel, unknown, E | E2, unknown, void, unknown> = pipe( + Ref.getAndSet(sinkLeftovers, Chunk.empty()), + Effect.flatMap((leftovers) => { + if (Chunk.isNonEmpty(leftovers)) { return pipe( - Handoff.take(handoff), - Effect.map((signal) => { - switch (signal._tag) { - case HandoffSignal.OP_EMIT: { + Ref.set(consumed, true), + Effect.zipRight(Effect.succeed(pipe( + core.write(leftovers), + core.flatMap(() => handoffConsumer) + ))) + ) + } + return pipe( + Handoff.take(handoff), + Effect.map((signal) => { + switch (signal._tag) { + case HandoffSignal.OP_EMIT: { + return pipe( + core.fromEffect(Ref.set(consumed, true)), + channel.zipRight(core.write(signal.elements)), + channel.zipRight(core.fromEffect(Ref.get(endAfterEmit))), + core.flatMap((bool) => bool ? core.unit : handoffConsumer) + ) + } + case HandoffSignal.OP_HALT: { + return core.failCause(signal.cause) + } + case HandoffSignal.OP_END: { + if (signal.reason._tag === SinkEndReason.OP_SCHEDULE_END) { return pipe( - core.fromEffect(Ref.set(consumed, true)), - channel.zipRight(core.write(signal.elements)), - channel.zipRight(core.fromEffect(Ref.get(endAfterEmit))), - core.flatMap((bool) => bool ? core.unit : handoffConsumer) - ) - } - case HandoffSignal.OP_HALT: { - return core.failCause(signal.cause) - } - case HandoffSignal.OP_END: { - if (signal.reason._tag === SinkEndReason.OP_SCHEDULE_END) { - return pipe( - Ref.get(consumed), - Effect.map((bool) => - bool ? + Ref.get(consumed), + Effect.map((bool) => + bool ? + core.fromEffect( + pipe( + Ref.set(sinkEndReason, SinkEndReason.ScheduleEnd), + Effect.zipRight(Ref.set(endAfterEmit, true)) + ) + ) : + pipe( core.fromEffect( pipe( Ref.set(sinkEndReason, SinkEndReason.ScheduleEnd), Effect.zipRight(Ref.set(endAfterEmit, true)) ) - ) : - pipe( - core.fromEffect( - pipe( - Ref.set(sinkEndReason, SinkEndReason.ScheduleEnd), - Effect.zipRight(Ref.set(endAfterEmit, true)) - ) - ), - core.flatMap(() => handoffConsumer) - ) - ), - channel.unwrap - ) - } - return pipe( - Ref.set(sinkEndReason, signal.reason), - Effect.zipRight(Ref.set(endAfterEmit, true)), - core.fromEffect + ), + core.flatMap(() => handoffConsumer) + ) + ), + channel.unwrap ) } + return pipe( + Ref.set(sinkEndReason, signal.reason), + Effect.zipRight(Ref.set(endAfterEmit, true)), + core.fromEffect + ) } - }) - ) - }), - channel.unwrap - ) + } + }) + ) + }), + channel.unwrap + ) const timeout = (lastB: Option.Option): Effect.Effect, R2 | R3> => scheduleDriver.next(lastB) const scheduledAggregator = ( sinkFiber: Fiber.RuntimeFiber>, B], E | E2>, scheduleFiber: Fiber.RuntimeFiber>, scope: Scope.Scope - ): Channel.Channel>, unknown> => { + ): Channel.Channel>, unknown, E | E2, unknown, unknown, unknown, R2 | R3> => { const forkSink = pipe( Ref.set(consumed, false), Effect.zipRight(Ref.set(endAfterEmit, false)), @@ -303,7 +302,7 @@ export const aggregateWithinEither = dual< leftovers: Chunk.Chunk>, b: B, c: Option.Option - ): Channel.Channel>, unknown> => + ): Channel.Channel>, unknown, E | E2, unknown, unknown, unknown, R2 | R3> => pipe( Ref.set(sinkLeftovers, Chunk.flatten(leftovers)), Effect.zipRight( @@ -502,7 +501,7 @@ export const asyncEffect = ( ) ), Effect.map(() => { - const loop: Channel.Channel, void> = pipe( + const loop: Channel.Channel, unknown, E, unknown, void, unknown> = pipe( Queue.take(output), Effect.flatMap(_take.done), Effect.match({ @@ -562,7 +561,7 @@ export const asyncInterrupt = ( ), Effect.map(Either.match({ onLeft: (canceler) => { - const loop: Channel.Channel, void> = pipe( + const loop: Channel.Channel, unknown, E, unknown, void, unknown> = pipe( Queue.take(output), Effect.flatMap(_take.done), Effect.match({ @@ -683,7 +682,7 @@ export const branchAfter = dual< suspend(() => { const buffering = ( acc: Chunk.Chunk - ): Channel.Channel, unknown, E2, Chunk.Chunk, unknown> => + ): Channel.Channel, Chunk.Chunk, E2, never, unknown, unknown, R | R2> => core.readWith({ onInput: (input) => { const nextSize = acc.length + input.length @@ -699,7 +698,7 @@ export const branchAfter = dual< const running = ( prefix: Chunk.Chunk, leftover: Chunk.Chunk - ): Channel.Channel, unknown, E2, Chunk.Chunk, unknown> => + ): Channel.Channel, Chunk.Chunk, E2, never, unknown, unknown, R | R2> => core.pipeTo( channel.zipRight( core.write(leftover), @@ -843,7 +842,7 @@ export const buffer = dual< return new StreamImpl( channel.unwrapScoped( Effect.map(queue, (queue) => { - const process: Channel.Channel, void> = pipe( + const process: Channel.Channel, unknown, E, unknown, void, unknown> = pipe( core.fromEffect(Queue.take(queue)), core.flatMap(Exit.match({ onFailure: (cause) => @@ -883,7 +882,7 @@ export const bufferChunks = dual< return new StreamImpl( channel.unwrapScoped( Effect.map(queue, (queue) => { - const process: Channel.Channel, void> = pipe( + const process: Channel.Channel, unknown, E, unknown, void, unknown> = pipe( core.fromEffect(Queue.take(queue)), core.flatMap(_take.match({ onEnd: () => core.unit, @@ -946,7 +945,7 @@ const bufferUnbounded = (self: Stream.Stream): Stream.Stream { - const process: Channel.Channel, void> = pipe( + const process: Channel.Channel, unknown, E, unknown, void, unknown> = pipe( core.fromEffect(Queue.take(queue)), core.flatMap(_take.match({ onEnd: () => core.unit, @@ -962,13 +961,13 @@ const bufferUnbounded = (self: Stream.Stream): Stream.Stream( scoped: Effect.Effect, Deferred.Deferred]>, never, Scope.Scope>, - bufferChannel: Channel.Channel, void> -): Channel.Channel, void> => { + bufferChannel: Channel.Channel, unknown, E, unknown, void, unknown, R> +): Channel.Channel, unknown, E, unknown, void, unknown, R> => { const producer = ( queue: Queue.Queue, Deferred.Deferred]>, ref: Ref.Ref> - ): Channel.Channel, unknown, never, never, unknown> => { - const terminate = (take: Take.Take): Channel.Channel, unknown, never, never, unknown> => + ): Channel.Channel, never, E, unknown, unknown, R> => { + const terminate = (take: Take.Take): Channel.Channel, never, E, unknown, unknown, R> => pipe( Ref.get(ref), Effect.tap(Deferred.await), @@ -1004,8 +1003,8 @@ const bufferSignal = ( } const consumer = ( queue: Queue.Queue, Deferred.Deferred]> - ): Channel.Channel, void> => { - const process: Channel.Channel, void> = pipe( + ): Channel.Channel, unknown, E, unknown, void, unknown, R> => { + const process: Channel.Channel, unknown, E, unknown, void, unknown> = pipe( core.fromEffect(Queue.take(queue)), core.flatMap(([take, deferred]) => channel.zipRight( @@ -1218,7 +1217,7 @@ export const changesWith = dual< >(2, (self: Stream.Stream, f: (x: A, y: A) => boolean): Stream.Stream => { const writer = ( last: Option.Option - ): Channel.Channel, unknown, E, Chunk.Chunk, void> => + ): Channel.Channel, Chunk.Chunk, E, E, void, unknown> => core.readWithCause({ onInput: (input: Chunk.Chunk) => { const [newLast, newChunk] = Chunk.reduce( @@ -1259,7 +1258,7 @@ export const changesWithEffect = dual< ): Stream.Stream => { const writer = ( last: Option.Option - ): Channel.Channel, unknown, E | E2, Chunk.Chunk, void> => + ): Channel.Channel, Chunk.Chunk, E | E2, E | E2, void, unknown, R | R2> => core.readWithCause({ onInput: (input: Chunk.Chunk) => pipe( @@ -1358,7 +1357,7 @@ export const combine = dual< const producer = ( handoff: Handoff.Handoff>>, latch: Handoff.Handoff - ): Channel.Channel => + ): Channel.Channel => pipe( core.fromEffect(Handoff.take(latch)), channel.zipRight(core.readWithCause({ @@ -1462,7 +1461,7 @@ export const combineChunks = dual< const producer = ( handoff: Handoff.Handoff>, latch: Handoff.Handoff - ): Channel.Channel, unknown, never, never, unknown> => + ): Channel.Channel, never, Err, unknown, unknown, R> => channel.zipRight( core.fromEffect(Handoff.take(latch)), core.readWithCause({ @@ -1481,7 +1480,7 @@ export const combineChunks = dual< _take.failCause(cause) ) ), - onDone: (): Channel.Channel, unknown, never, never, unknown> => + onDone: (): Channel.Channel, never, Err, unknown, unknown, R> => core.fromEffect(Handoff.offer>(handoff, _take.end)) }) ) @@ -1643,7 +1642,7 @@ export const debounce = dual< Handoff.make>(), Effect.map((handoff) => { const enqueue = (last: Chunk.Chunk): Effect.Effect< - Channel.Channel, unknown> + Channel.Channel, unknown, E, unknown, unknown, unknown> > => pipe( Clock.sleep(duration), @@ -1652,7 +1651,7 @@ export const debounce = dual< grafter, Effect.map((fiber) => consumer(DebounceState.previous(fiber))) ) - const producer: Channel.Channel, unknown, E, never, unknown> = core + const producer: Channel.Channel, E, E, unknown, unknown> = core .readWithCause({ onInput: (input: Chunk.Chunk) => Option.match(Chunk.last(input), { @@ -1682,7 +1681,7 @@ export const debounce = dual< }) const consumer = ( state: DebounceState.DebounceState - ): Channel.Channel, unknown> => { + ): Channel.Channel, unknown, E, unknown, unknown, unknown> => { switch (state._tag) { case DebounceState.OP_NOT_STARTED: { return pipe( @@ -1758,18 +1757,17 @@ export const debounce = dual< } } } - const debounceChannel: Channel.Channel, unknown, E, Chunk.Chunk, unknown> = - pipe( - channel.fromInput(input), - core.pipeTo(producer), - channelExecutor.run, - Effect.forkScoped, - Effect.as(pipe( - consumer(DebounceState.notStarted), - core.embedInput, unknown>(input as any) - )), - channel.unwrapScoped - ) + const debounceChannel: Channel.Channel, Chunk.Chunk, E, E, unknown, unknown> = pipe( + channel.fromInput(input), + core.pipeTo(producer), + channelExecutor.run, + Effect.forkScoped, + Effect.as(pipe( + consumer(DebounceState.notStarted), + core.embedInput, unknown>(input as any) + )), + channel.unwrapScoped + ) return new StreamImpl(pipe(toChannel(self), core.pipeTo(debounceChannel))) }) ) @@ -2119,7 +2117,7 @@ export const drop = dual< (n: number) => (self: Stream.Stream) => Stream.Stream, (self: Stream.Stream, n: number) => Stream.Stream >(2, (self: Stream.Stream, n: number): Stream.Stream => { - const loop = (r: number): Channel.Channel, unknown, never, Chunk.Chunk, unknown> => + const loop = (r: number): Channel.Channel, Chunk.Chunk, never, never, unknown, unknown> => core.readWith({ onInput: (input: Chunk.Chunk) => { const dropped = pipe(input, Chunk.drop(r)) @@ -2130,7 +2128,7 @@ export const drop = dual< } return pipe( core.write(dropped), - channel.zipRight(channel.identityChannel, unknown>()) + channel.zipRight(channel.identityChannel, never, unknown>()) ) }, onFailure: core.fail, @@ -2149,7 +2147,7 @@ export const dropRight = dual< } return suspend(() => { const queue = new RingBuffer(n) - const reader: Channel.Channel, unknown, E, Chunk.Chunk, void> = core.readWith({ + const reader: Channel.Channel, Chunk.Chunk, E, E, void, unknown> = core.readWith({ onInput: (input: Chunk.Chunk) => { const outputs = pipe( input, @@ -2193,7 +2191,7 @@ export const dropUntilEffect = dual< self: Stream.Stream, predicate: (a: NoInfer) => Effect.Effect ): Stream.Stream => { - const loop: Channel.Channel, unknown, E | E2, Chunk.Chunk, unknown> = core.readWith({ + const loop: Channel.Channel, Chunk.Chunk, E | E2, E, unknown, unknown, R2> = core.readWith({ onInput: (input: Chunk.Chunk) => pipe( Effect.dropUntil(input, predicate), @@ -2205,7 +2203,7 @@ export const dropUntilEffect = dual< } return pipe( core.write(leftover), - channel.zipRight(channel.identityChannel, unknown>()) + channel.zipRight(channel.identityChannel, E | E2, unknown>()) ) }), channel.unwrap @@ -2222,7 +2220,7 @@ export const dropWhile = dual< (predicate: Predicate>) => (self: Stream.Stream) => Stream.Stream, (self: Stream.Stream, predicate: Predicate) => Stream.Stream >(2, (self: Stream.Stream, predicate: Predicate): Stream.Stream => { - const loop: Channel.Channel, unknown, never, Chunk.Chunk, unknown> = core.readWith({ + const loop: Channel.Channel, Chunk.Chunk, never, never, unknown, unknown> = core.readWith({ onInput: (input: Chunk.Chunk) => { const output = Chunk.dropWhile(input, predicate) if (Chunk.isEmpty(output)) { @@ -2230,7 +2228,7 @@ export const dropWhile = dual< } return channel.zipRight( core.write(output), - channel.identityChannel, unknown>() + channel.identityChannel, never, unknown>() ) }, onFailure: core.fail, @@ -2254,7 +2252,7 @@ export const dropWhileEffect = dual< self: Stream.Stream, predicate: (a: A) => Effect.Effect ): Stream.Stream => { - const loop: Channel.Channel, unknown, E | E2, Chunk.Chunk, unknown> = core.readWith({ + const loop: Channel.Channel, Chunk.Chunk, E | E2, E, unknown, unknown, R2> = core.readWith({ onInput: (input: Chunk.Chunk) => pipe( Effect.dropWhile(input, predicate), @@ -2266,7 +2264,7 @@ export const dropWhileEffect = dual< } return channel.zipRight( core.write(leftover), - channel.identityChannel, unknown>() + channel.identityChannel, E | E2, unknown>() ) }), channel.unwrap @@ -2376,7 +2374,7 @@ export const filterEffect = dual< ): Stream.Stream => { const loop = ( iterator: Iterator - ): Channel.Channel, unknown, E | E2, Chunk.Chunk, unknown> => { + ): Channel.Channel, Chunk.Chunk, E | E2, E, unknown, unknown, R2> => { const next = iterator.next() if (next.done) { return core.readWithCause({ @@ -2430,7 +2428,7 @@ export const filterMapEffect = dual< suspend(() => { const loop = ( iterator: Iterator - ): Channel.Channel, unknown, E | E2, Chunk.Chunk, unknown> => { + ): Channel.Channel, Chunk.Chunk, E | E2, E, unknown, unknown, R | R2> => { const next = iterator.next() if (next.done) { return core.readWithCause({ @@ -2462,7 +2460,7 @@ export const filterMapWhile = dual< >( 2, (self: Stream.Stream, pf: (a: A) => Option.Option) => { - const loop: Channel.Channel, unknown, E, Chunk.Chunk, unknown> = core.readWith({ + const loop: Channel.Channel, Chunk.Chunk, E, E, unknown, unknown> = core.readWith({ onInput: (input: Chunk.Chunk) => { const mapped = Chunk.filterMapWhile(input, pf) if (mapped.length === input.length) { @@ -2495,7 +2493,7 @@ export const filterMapWhileEffect = dual< suspend(() => { const loop = ( iterator: Iterator - ): Channel.Channel, unknown, E | E2, Chunk.Chunk, unknown> => { + ): Channel.Channel, Chunk.Chunk, E | E2, E, unknown, unknown, R | R2> => { const next = iterator.next() if (next.done) { return core.readWithCause({ @@ -2531,7 +2529,7 @@ export const find: { (self: Stream.Stream, refinement: Refinement): Stream.Stream (self: Stream.Stream, predicate: Predicate): Stream.Stream } = dual(2, (self: Stream.Stream, predicate: Predicate): Stream.Stream => { - const loop: Channel.Channel, unknown, E, Chunk.Chunk, unknown> = core.readWith({ + const loop: Channel.Channel, Chunk.Chunk, E, E, unknown, unknown, R> = core.readWith({ onInput: (input: Chunk.Chunk) => Option.match(Chunk.findFirst(input, predicate), { onNone: () => loop, @@ -2558,7 +2556,7 @@ export const findEffect: { self: Stream.Stream, predicate: (a: NoInfer) => Effect.Effect ): Stream.Stream => { - const loop: Channel.Channel, unknown, E | E2, Chunk.Chunk, unknown> = core.readWith({ + const loop: Channel.Channel, Chunk.Chunk, E | E2, E, unknown, unknown, R2> = core.readWith({ onInput: (input: Chunk.Chunk) => pipe( Effect.findFirst(input, predicate), @@ -2626,7 +2624,7 @@ export const flatMap = dual< as, Chunk.map((a) => toChannel(f(a))), Chunk.reduce( - core.unit as Channel.Channel, unknown>, + core.unit as Channel.Channel, unknown, E2, unknown, unknown, unknown, R2>, (left, right) => pipe(left, channel.zipRight(right)) ) ) @@ -2712,7 +2710,7 @@ export const flatten = dual< /** @internal */ export const flattenChunks = (self: Stream.Stream, E, R>): Stream.Stream => { - const flatten: Channel.Channel>, unknown, E, Chunk.Chunk, unknown> = core + const flatten: Channel.Channel, Chunk.Chunk>, E, E, unknown, unknown> = core .readWithCause({ onInput: (chunks: Chunk.Chunk>) => core.flatMap( @@ -2768,7 +2766,7 @@ export const flattenExitOption = ( ): Stream.Stream => { const processChunk = ( chunk: Chunk.Chunk>>, - cont: Channel.Channel>>, unknown, E | E2, Chunk.Chunk, unknown> + cont: Channel.Channel, Chunk.Chunk>>, E | E2, E, unknown, unknown, R> ) => { const [toEmit, rest] = pipe(chunk, Chunk.splitWhere((exit) => !Exit.isSuccess(exit))) const next = pipe( @@ -2798,13 +2796,13 @@ export const flattenExitOption = ( ) } const process: Channel.Channel< - R, - E, + Chunk.Chunk, Chunk.Chunk>>, - unknown, E | E2, - Chunk.Chunk, - unknown + E, + unknown, + unknown, + R > = core.readWithCause({ onInput: (chunk: Chunk.Chunk>>) => processChunk(chunk, process), onFailure: (cause) => core.failCause(cause), @@ -2849,13 +2847,13 @@ export const fromAsyncIterable = ( /** @internal */ export const fromChannel = ( - channel: Channel.Channel, unknown> + channel: Channel.Channel, unknown, E, unknown, unknown, unknown, R> ): Stream.Stream => new StreamImpl(channel) /** @internal */ export const toChannel = ( stream: Stream.Stream -): Channel.Channel, unknown> => { +): Channel.Channel, unknown, E, unknown, unknown, unknown, R> => { if ("channel" in stream) { return (stream as StreamImpl).channel } else if (Effect.isEffect(stream)) { @@ -2984,7 +2982,7 @@ export const fromIteratorSucceed = ( let builder: Array = [] const loop = ( iterator: Iterator - ): Channel.Channel, unknown> => + ): Channel.Channel, unknown, never, unknown, unknown, unknown> => pipe( Effect.sync(() => { let next: IteratorResult = iterator.next() @@ -3206,7 +3204,7 @@ export const groupAdjacentBy = dual< const groupAdjacent = ( state: Option.Option - ): Channel.Channel, unknown, never, Chunk.Chunk, unknown> => + ): Channel.Channel, Chunk.Chunk, never, never, unknown, unknown> => core.readWithCause({ onInput: (input: Chunk.Chunk) => { const [updatedState, output] = groupAdjacentByChunk(state, input) @@ -3277,7 +3275,7 @@ export const haltWhen = dual< ): Stream.Stream => { const writer = ( fiber: Fiber.Fiber<_, E2> - ): Channel.Channel, unknown, E | E2, Chunk.Chunk, void> => + ): Channel.Channel, Chunk.Chunk, E | E2, E | E2, void, unknown, R2> => pipe( Fiber.poll(fiber), Effect.map(Option.match({ @@ -3321,7 +3319,7 @@ export const haltWhenDeferred = dual< >( 2, (self: Stream.Stream, deferred: Deferred.Deferred<_, E2>): Stream.Stream => { - const writer: Channel.Channel, unknown, E | E2, Chunk.Chunk, void> = pipe( + const writer: Channel.Channel, Chunk.Chunk, E | E2, E | E2, void, unknown, R> = pipe( Deferred.poll(deferred), Effect.map(Option.match({ onNone: () => @@ -3345,7 +3343,7 @@ export const haltWhenDeferred = dual< /** @internal */ export const identityStream = (): Stream.Stream => new StreamImpl( - channel.identityChannel() as Channel.Channel, unknown> + channel.identityChannel() as Channel.Channel, unknown, E, unknown, unknown, unknown> ) /** @internal */ @@ -3385,7 +3383,7 @@ export const interleaveWith = dual< ): Stream.Stream => { const producer = ( handoff: Handoff.Handoff> - ): Channel.Channel => + ): Channel.Channel => core.readWithCause({ onInput: (value: A | A2) => core.flatMap( @@ -3433,7 +3431,7 @@ export const interleaveWith = dual< const process = ( leftDone: boolean, rightDone: boolean - ): Channel.Channel, void> => + ): Channel.Channel, boolean, E | E2 | E3, E | E2 | E3, void, unknown, R> => core.readWithCause({ onInput: (bool: boolean) => { if (bool && !leftDone) { @@ -3485,7 +3483,7 @@ export const intersperse = dual< core.suspend(() => { const writer = ( isFirst: boolean - ): Channel.Channel, unknown, E, Chunk.Chunk, unknown> => + ): Channel.Channel, Chunk.Chunk, E, E, unknown, unknown> => core.readWithCause({ onInput: (chunk: Chunk.Chunk) => { const builder: Array = [] @@ -3615,7 +3613,7 @@ export const mapAccum = dual< s: S, f: (s: S, a: A) => readonly [S, A2] ): Stream.Stream => { - const accumulator = (s: S): Channel.Channel, unknown, E, Chunk.Chunk, void> => + const accumulator = (s: S): Channel.Channel, Chunk.Chunk, E, E, void, unknown> => core.readWith({ onInput: (input: Chunk.Chunk) => { const [nextS, chunk] = Chunk.mapAccum(input, s, f) @@ -3652,7 +3650,7 @@ export const mapAccumEffect = dual< suspend(() => { const accumulator = ( s: S - ): Channel.Channel, unknown, E | E2, Chunk.Chunk, unknown> => + ): Channel.Channel, Chunk.Chunk, E | E2, E, unknown, unknown, R | R2> => core.readWith({ onInput: (input: Chunk.Chunk) => pipe( @@ -3816,7 +3814,7 @@ export const mapEffectSequential = dual< ): Stream.Stream => { const loop = ( iterator: Iterator - ): Channel.Channel, unknown, E | E2, Chunk.Chunk, unknown> => { + ): Channel.Channel, Chunk.Chunk, E | E2, E, unknown, unknown, R2> => { const next = iterator.next() if (next.done) { return core.readWithCause({ @@ -4176,7 +4174,7 @@ export const orElseIfEmptyStream = dual< self: Stream.Stream, stream: LazyArg> ): Stream.Stream => { - const writer: Channel.Channel, unknown, E | E2, Chunk.Chunk, unknown> = core.readWith( + const writer: Channel.Channel, Chunk.Chunk, E | E2, E, unknown, unknown, R2> = core.readWith( { onInput: (input: Chunk.Chunk) => { if (Chunk.isEmpty(input)) { @@ -4184,7 +4182,7 @@ export const orElseIfEmptyStream = dual< } return pipe( core.write(input), - channel.zipRight(channel.identityChannel, unknown>()) + channel.zipRight(channel.identityChannel, E, unknown>()) ) }, onFailure: core.fail, @@ -4217,7 +4215,7 @@ export const paginateChunk = ( s: S, f: (s: S) => readonly [Chunk.Chunk, Option.Option] ): Stream.Stream => { - const loop = (s: S): Channel.Channel, unknown> => { + const loop = (s: S): Channel.Channel, unknown, never, unknown, unknown, unknown> => { const page = f(s) return Option.match(page[1], { onNone: () => channel.zipRight(core.write(page[0]), core.unit), @@ -4232,7 +4230,7 @@ export const paginateChunkEffect = ( s: S, f: (s: S) => Effect.Effect, Option.Option], E, R> ): Stream.Stream => { - const loop = (s: S): Channel.Channel, unknown> => + const loop = (s: S): Channel.Channel, unknown, E, unknown, unknown, unknown, R> => channel.unwrap( Effect.map(f(s), ([chunk, option]) => Option.match(option, { @@ -4296,15 +4294,7 @@ export const peel = dual< _sink.fail(error) ), onSuccess: ([z, leftovers]) => { - const loop: Channel.Channel< - never, - E, - Chunk.Chunk, - unknown, - E | E2, - Chunk.Chunk, - void - > = core + const loop: Channel.Channel, Chunk.Chunk, E | E2, E, void, unknown> = core .readWithCause({ onInput: (elements) => core.flatMap( @@ -4339,7 +4329,7 @@ export const peel = dual< } }) - const producer: Channel.Channel, void> = pipe( + const producer: Channel.Channel, unknown, E, unknown, void, unknown> = pipe( Handoff.take(handoff), Effect.map((signal) => { switch (signal._tag) { @@ -4524,34 +4514,34 @@ export const pipeThrough = dual< /** @internal */ export const pipeThroughChannel = dual< ( - channel: Channel.Channel, unknown, E2, Chunk.Chunk, unknown> + channel: Channel.Channel, Chunk.Chunk, E2, E, unknown, unknown, R2> ) => (self: Stream.Stream) => Stream.Stream, ( self: Stream.Stream, - channel: Channel.Channel, unknown, E2, Chunk.Chunk, unknown> + channel: Channel.Channel, Chunk.Chunk, E2, E, unknown, unknown, R2> ) => Stream.Stream >( 2, ( self: Stream.Stream, - channel: Channel.Channel, unknown, E2, Chunk.Chunk, unknown> + channel: Channel.Channel, Chunk.Chunk, E2, E, unknown, unknown, R2> ): Stream.Stream => new StreamImpl(pipe(toChannel(self), core.pipeTo(channel))) ) /** @internal */ export const pipeThroughChannelOrFail = dual< ( - chan: Channel.Channel, unknown, E2, Chunk.Chunk, unknown> + chan: Channel.Channel, Chunk.Chunk, E2, E, unknown, unknown, R2> ) => (self: Stream.Stream) => Stream.Stream, ( self: Stream.Stream, - chan: Channel.Channel, unknown, E2, Chunk.Chunk, unknown> + chan: Channel.Channel, Chunk.Chunk, E2, E, unknown, unknown, R2> ) => Stream.Stream >( 2, ( self: Stream.Stream, - chan: Channel.Channel, unknown, E2, Chunk.Chunk, unknown> + chan: Channel.Channel, Chunk.Chunk, E2, E, unknown, unknown, R2> ): Stream.Stream => new StreamImpl(pipe(toChannel(self), channel.pipeToOrFail(chan))) ) @@ -4715,7 +4705,7 @@ export const range = (min: number, max: number, chunkSize = DefaultChunkSize): S min: number, max: number, chunkSize: number - ): Channel.Channel, unknown> => { + ): Channel.Channel, unknown, never, unknown, unknown, unknown> => { const remaining = max - min + 1 if (remaining > chunkSize) { return pipe( @@ -4743,7 +4733,7 @@ export const rechunk = dual< const rechunkProcess = ( rechunker: StreamRechunker, target: number -): Channel.Channel, unknown, E, Chunk.Chunk, unknown> => +): Channel.Channel, Chunk.Chunk, E, E, unknown, unknown> => core.readWithCause({ onInput: (chunk: Chunk.Chunk) => { if (chunk.length === target && rechunker.isEmpty()) { @@ -4803,7 +4793,7 @@ class StreamRechunker { return undefined } - emitIfNotEmpty(): Channel.Channel, void> { + emitIfNotEmpty(): Channel.Channel, unknown, E, E, void, unknown> { if (this.pos !== 0) { return core.write(Chunk.unsafeFromArray(this.builder)) } @@ -4972,7 +4962,7 @@ export const repeatElementsWith = dual< Effect.map((driver) => { const feed = ( input: Chunk.Chunk - ): Channel.Channel, unknown, E, Chunk.Chunk, void> => + ): Channel.Channel, Chunk.Chunk, E, E, void, unknown, R2> => Option.match(Chunk.head(input), { onNone: () => loop, onSome: (a) => @@ -4984,13 +4974,13 @@ export const repeatElementsWith = dual< const step = ( input: Chunk.Chunk, a: A - ): Channel.Channel, unknown, E, Chunk.Chunk, void> => { + ): Channel.Channel, Chunk.Chunk, E, E, void, unknown, R2> => { const advance = pipe( driver.next(a), Effect.as(pipe(core.write(Chunk.of(options.onElement(a))), core.flatMap(() => step(input, a)))) ) const reset: Effect.Effect< - Channel.Channel, unknown, E, Chunk.Chunk, void>, + Channel.Channel, Chunk.Chunk, E, E, void, unknown, R2>, never, R2 > = pipe( @@ -5010,7 +5000,7 @@ export const repeatElementsWith = dual< ) return pipe(advance, Effect.orElse(() => reset), channel.unwrap) } - const loop: Channel.Channel, unknown, E, Chunk.Chunk, void> = core.readWith({ + const loop: Channel.Channel, Chunk.Chunk, E, E, void, unknown, R2> = core.readWith({ onInput: feed, onFailure: core.fail, onDone: () => core.unit @@ -5061,7 +5051,7 @@ export const repeatWith = dual< Effect.map((driver) => { const scheduleOutput = pipe(driver.last, Effect.orDie, Effect.map(options.onSchedule)) const process = pipe(self, map(options.onElement), toChannel) - const loop: Channel.Channel, void> = channel.unwrap( + const loop: Channel.Channel, unknown, E, unknown, void, unknown, R | R2> = channel.unwrap( Effect.match(driver.next(void 0), { onFailure: () => core.unit, onSuccess: () => @@ -5428,7 +5418,7 @@ export const runIntoQueueElementsScoped = dual< self: Stream.Stream, queue: Queue.Enqueue>> ): Effect.Effect => { - const writer: Channel.Channel, unknown, never, Exit.Exit>, unknown> = core + const writer: Channel.Channel>, Chunk.Chunk, never, E, unknown, unknown, R> = core .readWithCause({ onInput: (input: Chunk.Chunk) => core.flatMap( @@ -5459,7 +5449,7 @@ export const runIntoQueueScoped = dual< self: Stream.Stream, queue: Queue.Enqueue> ): Effect.Effect => { - const writer: Channel.Channel, unknown, never, Take.Take, unknown> = core + const writer: Channel.Channel, Chunk.Chunk, never, E, unknown, unknown, R> = core .readWithCause({ onInput: (input: Chunk.Chunk) => core.flatMap(core.write(_take.chunk(input)), () => writer), onFailure: (cause) => core.write(_take.failCause(cause)), @@ -5606,7 +5596,7 @@ export const scheduleWith = dual< const loop = ( driver: Schedule.ScheduleDriver, iterator: Iterator - ): Channel.Channel, unknown, E, Chunk.Chunk, unknown> => { + ): Channel.Channel, Chunk.Chunk, E, E, unknown, unknown, R2> => { const next = iterator.next() if (next.done) { return core.readWithCause({ @@ -5749,7 +5739,7 @@ export const slidingSize = dual< const queue = new RingBuffer(chunkSize) const emitOnStreamEnd = ( queueSize: number, - channelEnd: Channel.Channel, unknown, E, Chunk.Chunk>, unknown> + channelEnd: Channel.Channel>, Chunk.Chunk, E, E, unknown, unknown> ) => { if (queueSize < chunkSize) { const items = queue.toChunk() @@ -5767,7 +5757,7 @@ export const slidingSize = dual< } const reader = ( queueSize: number - ): Channel.Channel, unknown, E, Chunk.Chunk>, unknown> => + ): Channel.Channel>, Chunk.Chunk, E, E, unknown, unknown> => core.readWithCause({ onInput: (input: Chunk.Chunk) => core.flatMap( @@ -5799,7 +5789,7 @@ export const split = dual< const split = ( leftovers: Chunk.Chunk, input: Chunk.Chunk - ): Channel.Channel, unknown, E, Chunk.Chunk>, unknown> => { + ): Channel.Channel>, Chunk.Chunk, E, E, unknown, unknown, R> => { const [chunk, remaining] = pipe(leftovers, Chunk.appendAll(input), Chunk.splitWhere(predicate)) if (Chunk.isEmpty(chunk) || Chunk.isEmpty(remaining)) { return loop(pipe(chunk, Chunk.appendAll(pipe(remaining, Chunk.drop(1))))) @@ -5811,7 +5801,7 @@ export const split = dual< } const loop = ( leftovers: Chunk.Chunk - ): Channel.Channel, unknown, E, Chunk.Chunk>, unknown> => + ): Channel.Channel>, Chunk.Chunk, E, E, unknown, unknown, R> => core.readWith({ onInput: (input: Chunk.Chunk) => split(leftovers, input), onFailure: core.fail, @@ -5839,7 +5829,7 @@ export const splitOnChunk = dual< const next = ( leftover: Option.Option>, delimiterIndex: number - ): Channel.Channel, unknown, E, Chunk.Chunk>, unknown> => + ): Channel.Channel>, Chunk.Chunk, E, E, unknown, unknown, R> => core.readWithCause({ onInput: (inputChunk: Chunk.Chunk) => { let buffer: Array> | undefined @@ -5954,7 +5944,7 @@ export const splitLines = (self: Stream.Stream): Stream.Stre }) return Chunk.unsafeFromArray(chunkBuilder) } - const loop: Channel.Channel, unknown, E, Chunk.Chunk, unknown> = core + const loop: Channel.Channel, Chunk.Chunk, E, E, unknown, unknown, R> = core .readWithCause({ onInput: (input: Chunk.Chunk) => { const out = splitLinesChunk(input) @@ -5992,7 +5982,7 @@ export const take = dual< if (!Number.isInteger(n)) { return die(new Cause.IllegalArgumentException(`${n} must be an integer`)) } - const loop = (n: number): Channel.Channel, unknown, never, Chunk.Chunk, unknown> => + const loop = (n: number): Channel.Channel, Chunk.Chunk, never, never, unknown, unknown> => core.readWith({ onInput: (input: Chunk.Chunk) => { const taken = pipe(input, Chunk.take(Math.min(n, Number.POSITIVE_INFINITY))) @@ -6026,7 +6016,7 @@ export const takeRight = dual< pipe( Effect.succeed(new RingBuffer(n)), Effect.map((queue) => { - const reader: Channel.Channel, unknown, E, Chunk.Chunk, void> = core.readWith({ + const reader: Channel.Channel, Chunk.Chunk, E, E, void, unknown> = core.readWith({ onInput: (input: Chunk.Chunk) => { for (const element of input) { queue.put(element) @@ -6048,7 +6038,7 @@ export const takeUntil: { (predicate: Predicate>): (self: Stream.Stream) => Stream.Stream (self: Stream.Stream, predicate: Predicate): Stream.Stream } = dual(2, (self: Stream.Stream, predicate: Predicate): Stream.Stream => { - const loop: Channel.Channel, unknown, never, Chunk.Chunk, unknown> = core.readWith({ + const loop: Channel.Channel, Chunk.Chunk, never, never, unknown, unknown> = core.readWith({ onInput: (input: Chunk.Chunk) => { const taken = pipe(input, Chunk.takeWhile((a) => !predicate(a))) const last = pipe(input, Chunk.drop(taken.length), Chunk.take(1)) @@ -6080,7 +6070,7 @@ export const takeUntilEffect: { ): Stream.Stream => { const loop = ( iterator: Iterator - ): Channel.Channel, unknown, E | E2, Chunk.Chunk, unknown> => { + ): Channel.Channel, Chunk.Chunk, E | E2, E, unknown, unknown, R2> => { const next = iterator.next() if (next.done) { return core.readWithCause({ @@ -6115,7 +6105,7 @@ export const takeWhile: { (self: Stream.Stream, refinement: Refinement): Stream.Stream (self: Stream.Stream, predicate: Predicate): Stream.Stream } = dual(2, (self: Stream.Stream, predicate: Predicate): Stream.Stream => { - const loop: Channel.Channel, unknown, never, Chunk.Chunk, unknown> = core.readWith({ + const loop: Channel.Channel, Chunk.Chunk, never, never, unknown, unknown> = core.readWith({ onInput: (input: Chunk.Chunk) => { const taken = pipe(input, Chunk.takeWhile(predicate)) const more = taken.length === input.length @@ -6206,7 +6196,7 @@ export const tapErrorCause: { self: Stream.Stream, f: (cause: Cause.Cause) => Effect.Effect<_, E2, R2> ): Stream.Stream => { - const loop: Channel.Channel, unknown, E | E2, Chunk.Chunk, unknown> = core + const loop: Channel.Channel, Chunk.Chunk, E | E2, E, unknown, unknown, R | R2> = core .readWithCause({ onInput: (chunk) => core.flatMap(core.write(chunk), () => loop), onFailure: (cause) => core.fromEffect(Effect.zipRight(f(cause), Effect.failCause(cause))), @@ -6236,7 +6226,7 @@ export const tapSink = dual< fromEffect(Effect.all([Queue.bounded>(1), Deferred.make()])), flatMap(([queue, deferred]) => { const right = flattenTake(fromQueue(queue, { maxChunkSize: 1 })) - const loop: Channel.Channel, unknown, E | E2, Chunk.Chunk, unknown> = core + const loop: Channel.Channel, Chunk.Chunk, E | E2, E, unknown, unknown, R2> = core .readWithCause({ onInput: (chunk: Chunk.Chunk) => pipe( @@ -6245,7 +6235,7 @@ export const tapSink = dual< onFailure: () => core.flatMap(core.write(chunk), () => channel.identityChannel()), onSuccess: () => core.flatMap(core.write(chunk), () => loop) }) - ) as Channel.Channel, unknown, E | E2, Chunk.Chunk, unknown>, + ) as Channel.Channel, Chunk.Chunk, E | E2, E, unknown, unknown, R2>, onFailure: (cause: Cause.Cause) => pipe( core.fromEffect(Queue.offer(queue, _take.failCause(cause))), @@ -6374,7 +6364,7 @@ const throttleEnforceEffect = ( const loop = ( tokens: number, timestampMillis: number - ): Channel.Channel, unknown, E | E2, Chunk.Chunk, void> => + ): Channel.Channel, Chunk.Chunk, E | E2, E, void, unknown, R2> => core.readWithCause({ onInput: (input: Chunk.Chunk) => pipe( @@ -6417,7 +6407,7 @@ const throttleShapeEffect = ( const loop = ( tokens: number, timestampMillis: number - ): Channel.Channel, unknown, E | E2, Chunk.Chunk, void> => + ): Channel.Channel, Chunk.Chunk, E | E2, E, void, unknown, R2> => core.readWithCause({ onInput: (input: Chunk.Chunk) => pipe( @@ -6724,7 +6714,7 @@ export const transduce = dual< const newChannel = core.suspend(() => { const leftovers = { ref: Chunk.empty>() } const upstreamDone = { ref: false } - const buffer: Channel.Channel, unknown, E, Chunk.Chunk, unknown> = core.suspend( + const buffer: Channel.Channel, Chunk.Chunk, E, E, unknown, unknown> = core.suspend( () => { const leftover = leftovers.ref if (Chunk.isEmpty(leftover)) { @@ -6744,7 +6734,7 @@ export const transduce = dual< leftovers.ref = concatenated return concatenated } - const upstreamMarker: Channel.Channel, unknown, E, Chunk.Chunk, unknown> = core + const upstreamMarker: Channel.Channel, Chunk.Chunk, E, E, unknown, unknown> = core .readWith({ onInput: (input: Chunk.Chunk) => core.flatMap(core.write(input), () => upstreamMarker), onFailure: core.fail, @@ -6756,7 +6746,7 @@ export const transduce = dual< core.succeedNow(done) ) }) - const transducer: Channel.Channel, unknown, E | E2, Chunk.Chunk, void> = pipe( + const transducer: Channel.Channel, Chunk.Chunk, E | E2, never, void, unknown, R | R2> = pipe( sink, _sink.toChannel, core.collectElements, @@ -6792,7 +6782,7 @@ export const unfoldChunk = ( s: S, f: (s: S) => Option.Option, S]> ): Stream.Stream => { - const loop = (s: S): Channel.Channel, unknown> => + const loop = (s: S): Channel.Channel, unknown, never, unknown, unknown, unknown> => Option.match(f(s), { onNone: () => core.unit, onSome: ([chunk, s]) => core.flatMap(core.write(chunk), () => loop(s)) @@ -6806,7 +6796,7 @@ export const unfoldChunkEffect = ( f: (s: S) => Effect.Effect, S]>, E, R> ): Stream.Stream => suspend(() => { - const loop = (s: S): Channel.Channel, unknown> => + const loop = (s: S): Channel.Channel, unknown, E, unknown, unknown, unknown, R> => channel.unwrap( Effect.map( f(s), @@ -7976,7 +7966,7 @@ export const zipWithNext = ( ): Stream.Stream<[A, Option.Option], E, R> => { const process = ( last: Option.Option - ): Channel.Channel, unknown, never, Chunk.Chunk]>, void> => + ): Channel.Channel]>, Chunk.Chunk, never, never, void, unknown> => core.readWithCause({ onInput: (input: Chunk.Chunk) => { const [newLast, chunk] = Chunk.mapAccum( @@ -8145,8 +8135,8 @@ export const let_ = dual< // Circular with Channel /** @internal */ -export const channelToStream = ( - self: Channel.Channel, OutDone> +export const channelToStream = ( + self: Channel.Channel, unknown, OutErr, unknown, OutDone, unknown, Env> ): Stream.Stream => { return new StreamImpl(self) } diff --git a/packages/effect/test/Channel/reading.test.ts b/packages/effect/test/Channel/reading.test.ts index dd7fbf810c..6ef8fdfc4e 100644 --- a/packages/effect/test/Channel/reading.test.ts +++ b/packages/effect/test/Channel/reading.test.ts @@ -14,7 +14,7 @@ import { assert, describe } from "vitest" export const mapper = ( f: (a: A) => B -): Channel.Channel => { +): Channel.Channel => { return Channel.readWith({ onInput: (a: A) => Channel.flatMap( @@ -28,7 +28,7 @@ export const mapper = ( export const refWriter = ( ref: Ref.Ref> -): Channel.Channel => { +): Channel.Channel => { return Channel.readWith({ onInput: (a: A) => Channel.flatMap( @@ -42,7 +42,7 @@ export const refWriter = ( export const refReader = ( ref: Ref.Ref> -): Channel.Channel => { +): Channel.Channel => { return pipe( Channel.fromEffect( Ref.modify(ref, (array) => { @@ -104,7 +104,7 @@ describe("Channel", () => { const innerChannel = pipe( Channel.fromEffect(Ref.make>([])), Channel.flatMap((ref) => { - const inner = (): Channel.Channel => + const inner = (): Channel.Channel => Channel.readWith({ onInput: (input: number) => pipe( @@ -137,18 +137,16 @@ describe("Channel", () => { it.effect("read pipelining 2", () => Effect.gen(function*($) { const ref = yield* $(Ref.make>([])) - const intProducer: Channel.Channel< - never, - unknown, - unknown, - unknown, - never, - number, - void - > = Channel.writeAll(1, 2, 3, 4, 5) + const intProducer: Channel.Channel = Channel.writeAll( + 1, + 2, + 3, + 4, + 5 + ) const readIntsN = ( n: number - ): Channel.Channel => + ): Channel.Channel => n > 0 ? Channel.readWith({ onInput: (i: number) => pipe(Channel.write(i), Channel.flatMap(() => readIntsN(n - 1))), @@ -160,7 +158,7 @@ describe("Channel", () => { const sum = ( label: string, n: number - ): Channel.Channel => + ): Channel.Channel => Channel.readWith({ onInput: (input: number) => sum(label, n + input), onFailure: () => Channel.fromEffect(Ref.update(ref, (array) => [...array, n])), diff --git a/packages/experimental/src/MsgPack.ts b/packages/experimental/src/MsgPack.ts index 6c38ff4a21..3e0fa8360b 100644 --- a/packages/experimental/src/MsgPack.ts +++ b/packages/experimental/src/MsgPack.ts @@ -25,13 +25,12 @@ export class MsgPackError extends Data.TaggedError("MsgPackError")<{ * @category constructors */ export const pack = (): Channel.Channel< - never, - IE, + Chunk.Chunk, Chunk.Chunk, - unknown, IE | MsgPackError, - Chunk.Chunk, - void + IE, + void, + unknown > => Channel.flatMap( Channel.sync(() => new Packr()), @@ -45,19 +44,12 @@ export const pack = (): Channel.Channel< Channel.write ) - const loop: Channel.Channel< - never, - IE, - Chunk.Chunk, - unknown, - IE | MsgPackError, - Chunk.Chunk, - void - > = Channel.readWithCause({ - onInput: (input: Chunk.Chunk) => Channel.zipRight(pack(input), loop), - onFailure: (cause) => Channel.failCause(cause), - onDone: () => Channel.unit - }) + const loop: Channel.Channel, Chunk.Chunk, IE | MsgPackError, IE, void, unknown> = + Channel.readWithCause({ + onInput: (input: Chunk.Chunk) => Channel.zipRight(pack(input), loop), + onFailure: (cause) => Channel.failCause(cause), + onDone: () => Channel.unit + }) return loop } ) @@ -70,16 +62,16 @@ export const packSchema = ( schema: Schema.Schema ) => (): Channel.Channel< - R, - IE, + Chunk.Chunk, Chunk.Chunk, - unknown, IE | MsgPackError | ParseError, - Chunk.Chunk, - void + IE, + void, + unknown, + R > => { const encode = Schema.encode(Schema.chunkFromSelf(schema)) - const loop: Channel.Channel, unknown, IE | ParseError, Chunk.Chunk, unknown> = Channel + const loop: Channel.Channel, Chunk.Chunk, IE | ParseError, IE, unknown, unknown, R> = Channel .readWithCause({ onInput: (input: Chunk.Chunk) => Channel.zipRight( @@ -97,13 +89,12 @@ export const packSchema = ( * @category constructors */ export const unpack = (): Channel.Channel< - never, - IE, + Chunk.Chunk, Chunk.Chunk, - unknown, IE | MsgPackError, - Chunk.Chunk, - void + IE, + void, + unknown > => Channel.flatMap( Channel.sync(() => new Unpackr()), @@ -137,19 +128,12 @@ export const unpack = (): Channel.Channel< Channel.write ) - const loop: Channel.Channel< - never, - IE, - Chunk.Chunk, - unknown, - IE | MsgPackError, - Chunk.Chunk, - void - > = Channel.readWithCause({ - onInput: (input: Chunk.Chunk) => Channel.zipRight(unpack(input), loop), - onFailure: (cause) => Channel.failCause(cause), - onDone: () => Channel.unit - }) + const loop: Channel.Channel, Chunk.Chunk, IE | MsgPackError, IE, void, unknown> = + Channel.readWithCause({ + onInput: (input: Chunk.Chunk) => Channel.zipRight(unpack(input), loop), + onFailure: (cause) => Channel.failCause(cause), + onDone: () => Channel.unit + }) return loop } @@ -163,13 +147,13 @@ export const unpackSchema = ( schema: Schema.Schema ) => (): Channel.Channel< - R, - IE, + Chunk.Chunk, Chunk.Chunk, - unknown, MsgPackError | ParseError | IE, - Chunk.Chunk, - void + IE, + void, + unknown, + R > => { const parse = Schema.decodeUnknown(Schema.chunkFromSelf(schema)) return Channel.mapOutEffect(unpack(), parse) @@ -180,24 +164,8 @@ export const unpackSchema = ( * @category combinators */ export const duplex = ( - self: Channel.Channel< - R, - IE | MsgPackError, - Chunk.Chunk, - unknown, - OE, - Chunk.Chunk, - void - > -): Channel.Channel< - R, - IE, - Chunk.Chunk, - unknown, - MsgPackError | OE, - Chunk.Chunk, - void -> => + self: Channel.Channel, Chunk.Chunk, OE, IE | MsgPackError, void, unknown, R> +): Channel.Channel, Chunk.Chunk, MsgPackError | OE, IE, void, unknown, R> => Channel.pipeTo( Channel.pipeTo(pack(), self), unpack() @@ -215,45 +183,45 @@ export const duplexSchema: { } ): ( self: Channel.Channel< - R, - MsgPackError | ParseError | InErr, Chunk.Chunk, - unknown, - OutErr, Chunk.Chunk, - void + OutErr, + MsgPackError | ParseError | InErr, + void, + unknown, + R > ) => Channel.Channel< - IR | OR | R, - InErr, + Chunk.Chunk, Chunk.Chunk, - unknown, MsgPackError | ParseError | OutErr, - Chunk.Chunk, - void + InErr, + void, + unknown, + IR | OR | R > ( self: Channel.Channel< - R, - MsgPackError | ParseError | InErr, Chunk.Chunk, - unknown, - OutErr, Chunk.Chunk, - void + OutErr, + MsgPackError | ParseError | InErr, + void, + unknown, + R >, options: { readonly inputSchema: Schema.Schema readonly outputSchema: Schema.Schema } ): Channel.Channel< - R | IR | OR, - InErr, + Chunk.Chunk, Chunk.Chunk, - unknown, MsgPackError | ParseError | OutErr, - Chunk.Chunk, - void + InErr, + void, + unknown, + R | IR | OR > } = dual< ( @@ -263,68 +231,68 @@ export const duplexSchema: { } ) => ( self: Channel.Channel< - R, - MsgPackError | ParseError | InErr, Chunk.Chunk, - unknown, - OutErr, Chunk.Chunk, - void + OutErr, + MsgPackError | ParseError | InErr, + void, + unknown, + R > ) => Channel.Channel< - R | IR | OR, - InErr, + Chunk.Chunk, Chunk.Chunk, - unknown, MsgPackError | ParseError | OutErr, - Chunk.Chunk, - void + InErr, + void, + unknown, + R | IR | OR >, ( self: Channel.Channel< - R, - MsgPackError | ParseError | InErr, Chunk.Chunk, - unknown, - OutErr, Chunk.Chunk, - void + OutErr, + MsgPackError | ParseError | InErr, + void, + unknown, + R >, options: { readonly inputSchema: Schema.Schema readonly outputSchema: Schema.Schema } ) => Channel.Channel< - R | IR | OR, - InErr, + Chunk.Chunk, Chunk.Chunk, - unknown, MsgPackError | ParseError | OutErr, - Chunk.Chunk, - void + InErr, + void, + unknown, + R | IR | OR > >(2, ( self: Channel.Channel< - R, - MsgPackError | ParseError | InErr, Chunk.Chunk, - unknown, - OutErr, Chunk.Chunk, - void + OutErr, + MsgPackError | ParseError | InErr, + void, + unknown, + R >, options: { readonly inputSchema: Schema.Schema readonly outputSchema: Schema.Schema } ): Channel.Channel< - R | IR | OR, - InErr, + Chunk.Chunk, Chunk.Chunk, - unknown, MsgPackError | ParseError | OutErr, - Chunk.Chunk, - void + InErr, + void, + unknown, + R | IR | OR > => { const pack = packSchema(options.inputSchema) const unpack = unpackSchema(options.outputSchema) diff --git a/packages/experimental/src/Socket.ts b/packages/experimental/src/Socket.ts index 912a0d0921..6d79c9e092 100644 --- a/packages/experimental/src/Socket.ts +++ b/packages/experimental/src/Socket.ts @@ -70,7 +70,7 @@ export class SocketError extends Data.TaggedError("SocketError")<{ */ export const toChannel = ( self: Socket -): Channel.Channel, unknown, SocketError | IE, Chunk.Chunk, void> => +): Channel.Channel, Chunk.Chunk, SocketError | IE, IE, void, unknown> => Channel.unwrap( Effect.gen(function*(_) { const writeScope = yield* _(Scope.make()) @@ -104,21 +104,14 @@ export const toChannel = ( Effect.fork ) - const loop: Channel.Channel< - never, - unknown, - unknown, - unknown, - SocketError | IE, - Chunk.Chunk, - void - > = Channel.flatMap( - Queue.take(exitQueue), - Exit.match({ - onFailure: (cause) => Cause.isEmptyType(cause) ? Channel.unit : Channel.failCause(cause), - onSuccess: (chunk) => Channel.zipRight(Channel.write(chunk), loop) - }) - ) + const loop: Channel.Channel, unknown, SocketError | IE, unknown, void, unknown> = Channel + .flatMap( + Queue.take(exitQueue), + Exit.match({ + onFailure: (cause) => Cause.isEmptyType(cause) ? Channel.unit : Channel.failCause(cause), + onSuccess: (chunk) => Channel.zipRight(Channel.write(chunk), loop) + }) + ) return Channel.embedInput(loop, input) }) @@ -131,7 +124,7 @@ export const toChannel = ( export const toChannelWith = () => ( self: Socket -): Channel.Channel, unknown, SocketError | IE, Chunk.Chunk, void> => +): Channel.Channel, Chunk.Chunk, SocketError | IE, IE, void, unknown> => toChannel(self) /** @@ -139,13 +132,13 @@ export const toChannelWith = () => * @category constructors */ export const makeChannel = (): Channel.Channel< - Socket, - IE, Chunk.Chunk, - unknown, - SocketError | IE, Chunk.Chunk, - void + SocketError | IE, + IE, + void, + unknown, + Socket > => Channel.unwrap(Effect.map(Socket, toChannelWith())) /** @@ -284,15 +277,7 @@ export const makeWebSocketChannel = ( options?: { readonly closeCodeIsError?: (code: number) => boolean } -): Channel.Channel< - never, - IE, - Chunk.Chunk, - unknown, - SocketError | IE, - Chunk.Chunk, - void -> => +): Channel.Channel, Chunk.Chunk, SocketError | IE, IE, void, unknown> => Channel.unwrapScoped( Effect.map(makeWebSocket(url, options), toChannelWith()) ) diff --git a/packages/experimental/src/Socket/Node.ts b/packages/experimental/src/Socket/Node.ts index d68e872d0b..684059585e 100644 --- a/packages/experimental/src/Socket/Node.ts +++ b/packages/experimental/src/Socket/Node.ts @@ -139,15 +139,7 @@ export const fromNetSocket = ( */ export const makeNetChannel = ( options: Net.NetConnectOpts -): Channel.Channel< - never, - IE, - Chunk.Chunk, - unknown, - Socket.SocketError | IE, - Chunk.Chunk, - void -> => +): Channel.Channel, Chunk.Chunk, Socket.SocketError | IE, IE, void, unknown> => Channel.unwrapScoped( Effect.map(makeNet(options), Socket.toChannelWith()) ) diff --git a/packages/platform-node-shared/src/NodeSink.ts b/packages/platform-node-shared/src/NodeSink.ts index 7446a5cbcf..494f02c4b6 100644 --- a/packages/platform-node-shared/src/NodeSink.ts +++ b/packages/platform-node-shared/src/NodeSink.ts @@ -27,4 +27,4 @@ export const fromWritableChannel: ( writable: LazyArg, onError: (error: unknown) => OE, options?: FromWritableOptions -) => Channel, unknown, IE | OE, Chunk, void> = internal.fromWritableChannel +) => Channel, Chunk, IE | OE, IE, void, unknown> = internal.fromWritableChannel diff --git a/packages/platform-node-shared/src/NodeStream.ts b/packages/platform-node-shared/src/NodeStream.ts index 24ed6bc3cf..64cb30c715 100644 --- a/packages/platform-node-shared/src/NodeStream.ts +++ b/packages/platform-node-shared/src/NodeStream.ts @@ -47,7 +47,7 @@ export const fromReadableChannel: ( evaluate: LazyArg, onError: (error: unknown) => E, chunkSize: number | undefined -) => Channel, void> = internal.fromReadableChannel +) => Channel, unknown, E, unknown, void, unknown> = internal.fromReadableChannel /** * @category constructors @@ -57,7 +57,7 @@ export const fromDuplex: ( evaluate: LazyArg, onError: (error: unknown) => E, options?: FromReadableOptions & FromWritableOptions -) => Channel, unknown, IE | E, Chunk, void> = internal.fromDuplex +) => Channel, Chunk, IE | E, IE, void, unknown> = internal.fromDuplex /** * @category combinators diff --git a/packages/platform-node-shared/src/internal/sink.ts b/packages/platform-node-shared/src/internal/sink.ts index 9fed2a3ae8..44e18d0a74 100644 --- a/packages/platform-node-shared/src/internal/sink.ts +++ b/packages/platform-node-shared/src/internal/sink.ts @@ -20,7 +20,7 @@ export const fromWritableChannel = ( writable: LazyArg, onError: (error: unknown) => OE, options?: FromWritableOptions -): Channel.Channel, unknown, IE | OE, Chunk.Chunk, void> => +): Channel.Channel, Chunk.Chunk, IE | OE, IE, void, unknown> => Channel.flatMap( Effect.zip( Effect.sync(() => writable()), diff --git a/packages/platform-node-shared/src/internal/stream.ts b/packages/platform-node-shared/src/internal/stream.ts index 26656fbdb2..fa55b2975f 100644 --- a/packages/platform-node-shared/src/internal/stream.ts +++ b/packages/platform-node-shared/src/internal/stream.ts @@ -112,7 +112,7 @@ export const fromDuplex = ( evaluate: LazyArg, onError: (error: unknown) => E, options: FromReadableOptions & FromWritableOptions = {} -): Channel.Channel, unknown, IE | E, Chunk.Chunk, void> => +): Channel.Channel, Chunk.Chunk, IE | E, IE, void, unknown> => Channel.acquireUseRelease( Effect.tap( Effect.zip( @@ -194,7 +194,7 @@ export const fromReadableChannel = ( evaluate: LazyArg, onError: (error: unknown) => E, chunkSize: number | undefined -): Channel.Channel, void> => +): Channel.Channel, unknown, E, unknown, void, unknown> => Channel.acquireUseRelease( Effect.tap( Effect.zip( @@ -297,7 +297,7 @@ const readableTake = ( chunkSize: number | undefined ) => { const read = readChunkChannel(readable, chunkSize) - const loop: Channel.Channel, void> = Channel.flatMap( + const loop: Channel.Channel, unknown, E, unknown, void, unknown> = Channel.flatMap( Queue.take(queue), Either.match({ onLeft: Exit.match({ diff --git a/packages/platform/src/Http/Multipart.ts b/packages/platform/src/Http/Multipart.ts index 8936e7ece3..b6eb724c88 100644 --- a/packages/platform/src/Http/Multipart.ts +++ b/packages/platform/src/Http/Multipart.ts @@ -220,7 +220,7 @@ export const schemaPersisted: ( export const makeChannel: ( headers: Record, bufferSize?: number -) => Channel.Channel, unknown, MultipartError | IE, Chunk.Chunk, unknown> = +) => Channel.Channel, Chunk.Chunk, MultipartError | IE, IE, unknown, unknown> = internal.makeChannel /** diff --git a/packages/platform/src/internal/fileSystem.ts b/packages/platform/src/internal/fileSystem.ts index 5071547b81..44e40bb9a4 100644 --- a/packages/platform/src/internal/fileSystem.ts +++ b/packages/platform/src/internal/fileSystem.ts @@ -97,7 +97,7 @@ const stream = (file: File, { function loop( totalBytesRead: bigint - ): Channel.Channel, void> { + ): Channel.Channel, unknown, Error.PlatformError, unknown, void, unknown> { if (bytesToRead !== undefined && bytesToRead <= totalBytesRead) { return Channel.unit } diff --git a/packages/platform/src/internal/http/multipart.ts b/packages/platform/src/internal/http/multipart.ts index 06120ab416..f67b0863de 100644 --- a/packages/platform/src/internal/http/multipart.ts +++ b/packages/platform/src/internal/http/multipart.ts @@ -173,12 +173,11 @@ export const makeChannel = ( headers: Record, bufferSize = 16 ): Channel.Channel< - never, - IE, + Chunk.Chunk, Chunk.Chunk, - unknown, Multipart.MultipartError | IE, - Chunk.Chunk, + IE, + unknown, unknown > => Channel.acquireUseRelease( @@ -194,12 +193,11 @@ const makeFromQueue = ( config: MP.BaseConfig, queue: Queue.Queue | null> ): Channel.Channel< - never, - IE, + Chunk.Chunk, Chunk.Chunk, - unknown, IE | Multipart.MultipartError, - Chunk.Chunk, + IE, + unknown, unknown > => Channel.suspend(() => { @@ -229,7 +227,7 @@ const makeFromQueue = ( onFile(info) { let chunks: Array = [] let finished = false - const take: Channel.Channel, void> = Channel + const take: Channel.Channel, unknown, never, unknown, void, unknown> = Channel .suspend(() => { if (chunks.length === 0) { return finished ? Channel.unit : Channel.zipRight(pump, take) @@ -285,13 +283,12 @@ const makeFromQueue = ( ) const partsChannel: Channel.Channel< - never, - unknown, - unknown, + Chunk.Chunk, unknown, IE | Multipart.MultipartError, - Chunk.Chunk, - void + unknown, + void, + unknown > = Channel.suspend(() => { if (error._tag === "Some") { return Channel.failCause(error.value) @@ -351,7 +348,7 @@ class FileImpl implements Multipart.File { constructor( info: MP.PartInfo, - channel: Channel.Channel, void> + channel: Channel.Channel, unknown, never, unknown, void, unknown> ) { this[TypeId] = TypeId this.key = info.name diff --git a/packages/platform/src/internal/worker.ts b/packages/platform/src/internal/worker.ts index 3b1cb887fa..1a3a3ed024 100644 --- a/packages/platform/src/internal/worker.ts +++ b/packages/platform/src/internal/worker.ts @@ -220,8 +220,8 @@ export const makeManager = Effect.gen(function*(_) { executeRelease ), ([, queue]) => { - const loop: Channel.Channel, void> = - Channel.flatMap( + const loop: Channel.Channel, unknown, E | WorkerError, unknown, void, unknown> = Channel + .flatMap( Queue.take(queue), Exit.match({ onFailure: (cause) => Cause.isEmpty(cause) ? Channel.unit : Channel.failCause(cause),