diff --git a/.changeset/stream-tuple.md b/.changeset/stream-tuple.md new file mode 100644 index 0000000000..c03042a4fa --- /dev/null +++ b/.changeset/stream-tuple.md @@ -0,0 +1,5 @@ +--- +"effect": minor +--- + +refactor(Stream): use new built-in `Types.TupleOf` instead of `Stream.DynamicTuple` and deprecate it diff --git a/packages/effect/src/Stream.ts b/packages/effect/src/Stream.ts index c936af8f93..840db1a345 100644 --- a/packages/effect/src/Stream.ts +++ b/packages/effect/src/Stream.ts @@ -30,7 +30,7 @@ import type * as Emit from "./StreamEmit.js" import type * as HaltStrategy from "./StreamHaltStrategy.js" import type * as Take from "./Take.js" import type * as Tracer from "./Tracer.js" -import type { Covariant, NoInfer } from "./Types.js" +import type { Covariant, NoInfer, TupleOf } from "./Types.js" import type * as Unify from "./Unify.js" /** @@ -146,6 +146,7 @@ export declare namespace Stream { /** * @since 2.0.0 * @category models + * @deprecated use Types.TupleOf instead */ export type DynamicTuple = N extends N ? number extends N ? Array : DynamicTupleOf : never @@ -153,6 +154,7 @@ export declare namespace Stream { /** * @since 2.0.0 * @category models + * @deprecated use Types.TupleOf instead */ export type DynamicTupleOf> = R["length"] extends N ? R : DynamicTupleOf @@ -359,12 +361,12 @@ export const broadcast: { maximumLag: number ): ( self: Stream - ) => Effect.Effect, N>, never, Scope.Scope | R> + ) => Effect.Effect>, never, Scope.Scope | R> ( self: Stream, n: N, maximumLag: number - ): Effect.Effect, N>, never, Scope.Scope | R> + ): Effect.Effect>, never, Scope.Scope | R> } = internal.broadcast /** @@ -396,12 +398,12 @@ export const broadcastedQueues: { maximumLag: number ): ( self: Stream - ) => Effect.Effect>, N>, never, R | Scope.Scope> + ) => Effect.Effect>>, never, R | Scope.Scope> ( self: Stream, n: N, maximumLag: number - ): Effect.Effect>, N>, never, Scope.Scope | R> + ): Effect.Effect>>, never, Scope.Scope | R> } = internal.broadcastedQueues /** @@ -893,7 +895,7 @@ export const distributedWith: { } ): ( self: Stream - ) => Effect.Effect>>, N>, never, Scope.Scope | R> + ) => Effect.Effect>>>, never, Scope.Scope | R> ( self: Stream, options: { @@ -901,7 +903,7 @@ export const distributedWith: { readonly maximumLag: number readonly decide: (a: A) => Effect.Effect> } - ): Effect.Effect>>, N>, never, Scope.Scope | R> + ): Effect.Effect>>>, never, Scope.Scope | R> } = internal.distributedWith /** diff --git a/packages/effect/src/internal/stream.ts b/packages/effect/src/internal/stream.ts index 6b39555748..15c757e185 100644 --- a/packages/effect/src/internal/stream.ts +++ b/packages/effect/src/internal/stream.ts @@ -31,7 +31,7 @@ import * as HaltStrategy from "../StreamHaltStrategy.js" import type * as Take from "../Take.js" import type * as Tracer from "../Tracer.js" import * as Tuple from "../Tuple.js" -import type { NoInfer } from "../Types.js" +import type { NoInfer, TupleOf } from "../Types.js" import * as channel from "./channel.js" import * as channelExecutor from "./channel/channelExecutor.js" import * as MergeStrategy from "./channel/mergeStrategy.js" @@ -685,25 +685,22 @@ export const broadcast = dual< maximumLag: number ) => ( self: Stream.Stream - ) => Effect.Effect, N>, never, Scope.Scope | R>, + ) => Effect.Effect>, never, Scope.Scope | R>, ( self: Stream.Stream, n: N, maximumLag: number - ) => Effect.Effect, N>, never, Scope.Scope | R> + ) => Effect.Effect>, never, Scope.Scope | R> >(3, ( self: Stream.Stream, n: N, maximumLag: number -): Effect.Effect, N>, never, Scope.Scope | R> => +): Effect.Effect>, never, Scope.Scope | R> => pipe( self, broadcastedQueues(n, maximumLag), Effect.map((tuple) => - tuple.map((queue) => flattenTake(fromQueue(queue, { shutdown: true }))) as Stream.Stream.DynamicTuple< - Stream.Stream, - N - > + tuple.map((queue) => flattenTake(fromQueue(queue, { shutdown: true }))) as TupleOf> ) )) @@ -733,21 +730,21 @@ export const broadcastedQueues = dual< maximumLag: number ) => ( self: Stream.Stream - ) => Effect.Effect>, N>, never, Scope.Scope | R>, + ) => Effect.Effect>>, never, Scope.Scope | R>, ( self: Stream.Stream, n: N, maximumLag: number - ) => Effect.Effect>, N>, never, Scope.Scope | R> + ) => Effect.Effect>>, never, Scope.Scope | R> >(3, ( self: Stream.Stream, n: N, maximumLag: number -): Effect.Effect>, N>, never, Scope.Scope | R> => +): Effect.Effect>>, never, Scope.Scope | R> => Effect.flatMap(PubSub.bounded>(maximumLag), (pubsub) => pipe( Effect.all(Array.from({ length: n }, () => PubSub.subscribe(pubsub))) as Effect.Effect< - Stream.Stream.DynamicTuple>, N>, + TupleOf>>, never, R >, @@ -1764,7 +1761,7 @@ export const distributedWith = dual< ) => ( self: Stream.Stream ) => Effect.Effect< - Stream.Stream.DynamicTuple>>, N>, + TupleOf>>>, never, Scope.Scope | R >, @@ -1776,7 +1773,7 @@ export const distributedWith = dual< readonly decide: (a: A) => Effect.Effect> } ) => Effect.Effect< - Stream.Stream.DynamicTuple>>, N>, + TupleOf>>>, never, Scope.Scope | R > @@ -1790,7 +1787,7 @@ export const distributedWith = dual< readonly decide: (a: A) => Effect.Effect> } ): Effect.Effect< - Stream.Stream.DynamicTuple>>, N>, + TupleOf>>>, never, Scope.Scope | R > => @@ -1829,7 +1826,7 @@ export const distributedWith = dual< Deferred.succeed(deferred, (a: A) => Effect.map(options.decide(a), (f) => (key: number) => pipe(f(mappings.get(key)!)))), Effect.as( - Array.from(queues) as Stream.Stream.DynamicTuple>>, N> + Array.from(queues) as TupleOf>>> ) ) })