diff --git a/.changeset/tall-planets-search.md b/.changeset/tall-planets-search.md new file mode 100644 index 0000000..dcb8da0 --- /dev/null +++ b/.changeset/tall-planets-search.md @@ -0,0 +1,5 @@ +--- +"@effect/stream": patch +--- + +refactor Scope elimination in signatures diff --git a/docs/modules/Channel.ts.md b/docs/modules/Channel.ts.md index 6cd7e60..bbe4e54 100644 --- a/docs/modules/Channel.ts.md +++ b/docs/modules/Channel.ts.md @@ -530,7 +530,7 @@ Use a scoped effect to emit an output element. ```ts export declare const scoped: ( - effect: Effect.Effect + effect: Effect.Effect ) => Channel, unknown, unknown, unknown, E, A, unknown> ``` @@ -594,7 +594,7 @@ Makes a channel from a managed that returns a channel in case of success. ```ts export declare const unwrapScoped: ( - self: Effect.Effect> + self: Effect.Effect> ) => Channel, InErr, InElem, InDone, E | OutErr, OutElem, OutDone> ``` diff --git a/docs/modules/Sink.ts.md b/docs/modules/Sink.ts.md index cf0ad0b..7405daa 100644 --- a/docs/modules/Sink.ts.md +++ b/docs/modules/Sink.ts.md @@ -891,11 +891,11 @@ Creates a sink from a chunk processing function. ```ts export declare const fromPush: ( push: Effect.Effect< - Scope.Scope | R, + R, never, (_: Option.Option>) => Effect.Effect, Chunk.Chunk], void> > -) => Sink +) => Sink, E, In, L, Z> ``` Added in v1.0.0 @@ -1095,8 +1095,8 @@ Creates a sink produced from a scoped effect. ```ts export declare const unwrapScoped: ( - effect: Effect.Effect> -) => Sink + effect: Effect.Effect> +) => Sink, E, In, L, Z> ``` Added in v1.0.0 diff --git a/docs/modules/Stream.ts.md b/docs/modules/Stream.ts.md index 312c519..b3fd7ac 100644 --- a/docs/modules/Stream.ts.md +++ b/docs/modules/Stream.ts.md @@ -465,9 +465,9 @@ end of the stream, by setting it to `None`. ```ts export declare const asyncScoped: ( - register: (emit: Emit.Emit) => Effect.Effect, + register: (emit: Emit.Emit) => Effect.Effect, outputBuffer?: number -) => Stream +) => Stream, E, A> ``` Added in v1.0.0 @@ -1066,9 +1066,7 @@ Creates a single-valued stream from a scoped resource. **Signature** ```ts -export declare const scoped: ( - effect: Effect.Effect -) => Stream, E, A> +export declare const scoped: (effect: Effect.Effect) => Stream, E, A> ``` Added in v1.0.0 @@ -1228,7 +1226,7 @@ Creates a stream produced from a scoped `Effect`. ```ts export declare const unwrapScoped: ( - effect: Effect.Effect> + effect: Effect.Effect> ) => Stream, E | E2, A> ``` diff --git a/src/Channel.ts b/src/Channel.ts index 5b8e85d..266a98d 100644 --- a/src/Channel.ts +++ b/src/Channel.ts @@ -1925,7 +1925,7 @@ export const runDrain: ( * @category constructors */ export const scoped: ( - effect: Effect.Effect + effect: Effect.Effect ) => Channel, unknown, unknown, unknown, E, A, unknown> = channel.scoped /** @@ -2022,7 +2022,7 @@ export const unwrap: * @category constructors */ export const unwrapScoped: ( - self: Effect.Effect> + self: Effect.Effect> ) => Channel, InErr, InElem, InDone, E | OutErr, OutElem, OutDone> = channel.unwrapScoped /** diff --git a/src/Sink.ts b/src/Sink.ts index 7a23769..71b70c4 100644 --- a/src/Sink.ts +++ b/src/Sink.ts @@ -1002,11 +1002,11 @@ export const fromHub: ( */ export const fromPush: ( push: Effect.Effect< - Scope.Scope | R, + R, never, (_: Option.Option>) => Effect.Effect, Chunk.Chunk], void> > -) => Sink = internal.fromPush +) => Sink, E, In, L, Z> = internal.fromPush /** * Create a sink which enqueues each element into the specified queue. @@ -1332,8 +1332,8 @@ export const unwrap: ( * @category constructors */ export const unwrapScoped: ( - effect: Effect.Effect> -) => Sink = internal.unwrapScoped + effect: Effect.Effect> +) => Sink, E, In, L, Z> = internal.unwrapScoped /** * Returns the sink that executes this one and times its execution. diff --git a/src/Stream.ts b/src/Stream.ts index cdf9afb..888ef76 100644 --- a/src/Stream.ts +++ b/src/Stream.ts @@ -303,9 +303,9 @@ export const asyncOption: ( * @category constructors */ export const asyncScoped: ( - register: (emit: Emit.Emit) => Effect.Effect, + register: (emit: Emit.Emit) => Effect.Effect, outputBuffer?: number -) => Stream = internal.asyncScoped +) => Stream, E, A> = internal.asyncScoped /** * Returns a `Stream` that first collects `n` elements from the input `Stream`, @@ -3329,7 +3329,7 @@ export const scheduleWith: { * @since 1.0.0 * @category constructors */ -export const scoped: (effect: Effect.Effect) => Stream, E, A> = +export const scoped: (effect: Effect.Effect) => Stream, E, A> = internal.scoped /** @@ -3915,8 +3915,8 @@ export const unwrap: (effect: Effect.Effect( - effect: Effect.Effect> -) => Stream | R2, E | E2, A> = internal.unwrapScoped + effect: Effect.Effect> +) => Stream, E | E2, A> = internal.unwrapScoped /** * Updates the specified service within the context of the `Stream`. diff --git a/src/internal/channel.ts b/src/internal/channel.ts index 80a8878..bbf541d 100644 --- a/src/internal/channel.ts +++ b/src/internal/channel.ts @@ -2127,8 +2127,8 @@ export const runDrain = ( /** @internal */ export const scoped = ( - effect: Effect.Effect -): Channel.Channel, unknown, unknown, unknown, E, A, unknown> => + effect: Effect.Effect +): Channel.Channel, unknown, unknown, unknown, E, A, unknown> => unwrap( Effect.uninterruptibleMask((restore) => Effect.map(Scope.make(), (scope) => @@ -2259,13 +2259,9 @@ export const unwrapScoped = < OutElem, OutDone >( - self: Effect.Effect< - R | Scope.Scope, - E, - Channel.Channel - > + self: Effect.Effect> ): Channel.Channel< - Exclude | Env, + Exclude | Env, InErr, InElem, InDone, diff --git a/src/internal/sink.ts b/src/internal/sink.ts index 91f217e..e5ce3c8 100644 --- a/src/internal/sink.ts +++ b/src/internal/sink.ts @@ -1462,11 +1462,12 @@ export const fromHub = ( /** @internal */ export const fromPush = ( push: Effect.Effect< - R | Scope.Scope, + R, never, (_: Option.Option>) => Effect.Effect, Chunk.Chunk], void> > -): Sink.Sink => new SinkImpl(channel.unwrapScoped(pipe(push, Effect.map(fromPushPull)))) +): Sink.Sink, E, In, L, Z> => + new SinkImpl(channel.unwrapScoped(pipe(push, Effect.map(fromPushPull)))) const fromPushPull = ( push: ( @@ -1969,8 +1970,8 @@ export const unwrap = ( /** @internal */ export const unwrapScoped = ( - effect: Effect.Effect> -): Sink.Sink => { + effect: Effect.Effect> +): Sink.Sink, E, In, L, Z> => { return new SinkImpl(channel.unwrapScoped(pipe(effect, Effect.map((sink) => toChannel(sink))))) } diff --git a/src/internal/stream.ts b/src/internal/stream.ts index 2a6ed9c..5e2627a 100644 --- a/src/internal/stream.ts +++ b/src/internal/stream.ts @@ -580,9 +580,9 @@ export const asyncOption = ( /** @internal */ export const asyncScoped = ( - register: (emit: Emit.Emit) => Effect.Effect, + register: (emit: Emit.Emit) => Effect.Effect, outputBuffer = 16 -): Stream.Stream => +): Stream.Stream, E, A> => pipe( Effect.acquireRelease( Queue.bounded>(outputBuffer), @@ -5622,8 +5622,8 @@ export const scanEffect = dual< /** @internal */ export const scoped = ( - effect: Effect.Effect -): Stream.Stream, E, A> => + effect: Effect.Effect +): Stream.Stream, E, A> => new StreamImpl(channel.ensuring(channel.scoped(pipe(effect, Effect.map(Chunk.of))), Effect.unit)) /** @internal */ @@ -6754,8 +6754,8 @@ export const unwrap = ( /** @internal */ export const unwrapScoped = ( - effect: Effect.Effect> -): Stream.Stream | R2, E | E2, A> => flatten(scoped(effect)) + effect: Effect.Effect> +): Stream.Stream | R2, E | E2, A> => flatten(scoped(effect)) /** @internal */ export const updateService = dual<