diff --git a/.changeset/stream-left-right.md b/.changeset/stream-left-right.md new file mode 100644 index 0000000000..0ead3fdbd7 --- /dev/null +++ b/.changeset/stream-left-right.md @@ -0,0 +1,5 @@ +--- +"effect": patch +--- + +Introduce left / right naming for Stream apis \ No newline at end of file diff --git a/packages/effect/src/Stream.ts b/packages/effect/src/Stream.ts index e35d77f01b..28598f96b3 100644 --- a/packages/effect/src/Stream.ts +++ b/packages/effect/src/Stream.ts @@ -1009,8 +1009,8 @@ export const concatAll: (streams: Chunk.Chunk>) => Stre /** * Composes this stream with the specified stream to create a cartesian - * product of elements. The `that` stream would be run multiple times, for - * every element in the `this` stream. + * product of elements. The `right` stream would be run multiple times, for + * every element in the `left` stream. * * See also `Stream.zip` for the more common point-wise variant. * @@ -1034,14 +1034,14 @@ export const concatAll: (streams: Chunk.Chunk>) => Stre * @category utils */ export const cross: { - (that: Stream): (self: Stream) => Stream<[A, A2], E2 | E, R2 | R> - (self: Stream, that: Stream): Stream<[A, A2], E | E2, R | R2> + (right: Stream): (left: Stream) => Stream<[AL, AR], EL | ER, RL | RR> + (left: Stream, right: Stream): Stream<[AL, AR], EL | ER, RL | RR> } = internal.cross /** * Composes this stream with the specified stream to create a cartesian - * product of elements, but keeps only elements from this stream. The `that` - * stream would be run multiple times, for every element in the `this` stream. + * product of elements, but keeps only elements from `left` stream. The `right` + * stream would be run multiple times, for every element in the `left` stream. * * See also `Stream.zipLeft` for the more common point-wise variant. * @@ -1049,14 +1049,14 @@ export const cross: { * @category utils */ export const crossLeft: { - (that: Stream): (self: Stream) => Stream - (self: Stream, that: Stream): Stream + (right: Stream): (left: Stream) => Stream + (left: Stream, right: Stream): Stream } = internal.crossLeft /** * Composes this stream with the specified stream to create a cartesian - * product of elements, but keeps only elements from the other stream. The - * `that` stream would be run multiple times, for every element in the `this` + * product of elements, but keeps only elements from the `right` stream. The + * `left` stream would be run multiple times, for every element in the `right` * stream. * * See also `Stream.zipRight` for the more common point-wise variant. @@ -1065,14 +1065,14 @@ export const crossLeft: { * @category utils */ export const crossRight: { - (that: Stream): (self: Stream) => Stream - (self: Stream, that: Stream): Stream + (right: Stream): (left: Stream) => Stream + (left: Stream, right: Stream): Stream } = internal.crossRight /** * Composes this stream with the specified stream to create a cartesian - * product of elements with a specified function. The `that` stream would be - * run multiple times, for every element in the `this` stream. + * product of elements with a specified function. The `right` stream would be + * run multiple times, for every element in the `left` stream. * * See also `Stream.zipWith` for the more common point-wise variant. * @@ -1080,15 +1080,15 @@ export const crossRight: { * @category utils */ export const crossWith: { - ( - that: Stream, - f: (a: A, b: B) => C - ): (self: Stream) => Stream - ( - self: Stream, - that: Stream, - f: (a: A, b: B) => C - ): Stream + ( + right: Stream, + f: (left: AL, right: AR) => A + ): (left: Stream) => Stream + ( + left: Stream, + right: Stream, + f: (left: AL, right: AR) => A + ): Stream } = internal.crossWith /** @@ -5519,8 +5519,8 @@ export const zipAllWith: { * @category zipping */ export const zipLatest: { - (that: Stream): (self: Stream) => Stream<[A, A2], E2 | E, R2 | R> - (self: Stream, that: Stream): Stream<[A, A2], E | E2, R | R2> + (right: Stream): (left: Stream) => Stream<[AL, AR], EL | ER, RL | RR> + (left: Stream, right: Stream): Stream<[AL, AR], EL | ER, RL | RR> } = internal.zipLatest /** @@ -5575,20 +5575,20 @@ export const zipLatestAll: >>( * @category zipping */ export const zipLatestWith: { - ( - that: Stream, - f: (a: A, a2: A2) => A3 - ): (self: Stream) => Stream - ( - self: Stream, - that: Stream, - f: (a: A, a2: A2) => A3 - ): Stream + ( + right: Stream, + f: (left: AL, right: AR) => A + ): (left: Stream) => Stream + ( + left: Stream, + right: Stream, + f: (left: AL, right: AR) => A + ): Stream } = internal.zipLatestWith /** * Zips this stream with another point-wise, but keeps only the outputs of - * this stream. + * `left` stream. * * The new stream will end when one of the sides ends. * @@ -5596,13 +5596,13 @@ export const zipLatestWith: { * @category zipping */ export const zipLeft: { - (that: Stream): (self: Stream) => Stream - (self: Stream, that: Stream): Stream + (right: Stream): (left: Stream) => Stream + (left: Stream, right: Stream): Stream } = internal.zipLeft /** * Zips this stream with another point-wise, but keeps only the outputs of the - * other stream. + * `right` stream. * * The new stream will end when one of the sides ends. * @@ -5610,8 +5610,8 @@ export const zipLeft: { * @category zipping */ export const zipRight: { - (that: Stream): (self: Stream) => Stream - (self: Stream, that: Stream): Stream + (right: Stream): (left: Stream) => Stream + (left: Stream, right: Stream): Stream } = internal.zipRight /** @@ -5637,15 +5637,15 @@ export const zipRight: { * @category zipping */ export const zipWith: { - ( - that: Stream, - f: (a: A, a2: A2) => A3 - ): (self: Stream) => Stream - ( - self: Stream, - that: Stream, - f: (a: A, a2: A2) => A3 - ): Stream + ( + right: Stream, + f: (left: AL, right: AR) => A + ): (left: Stream) => Stream + ( + left: Stream, + right: Stream, + f: (left: AL, right: AR) => A + ): Stream } = internal.zipWith /** diff --git a/packages/effect/src/internal/stream.ts b/packages/effect/src/internal/stream.ts index 459827d6bc..0f548bb835 100644 --- a/packages/effect/src/internal/stream.ts +++ b/packages/effect/src/internal/stream.ts @@ -1680,74 +1680,74 @@ export const concatAll = (streams: Chunk.Chunk>) suspend(() => pipe(streams, Chunk.reduce(empty as Stream.Stream, (x, y) => concat(y)(x)))) /** @internal */ -export const cross = dual< - ( - that: Stream.Stream - ) => (self: Stream.Stream) => Stream.Stream<[A, A2], E2 | E, R2 | R>, - ( - self: Stream.Stream, - that: Stream.Stream - ) => Stream.Stream<[A, A2], E2 | E, R2 | R> ->( +export const cross: { + ( + right: Stream.Stream + ): (left: Stream.Stream) => Stream.Stream<[AL, AR], EL | ER, RL | RR> + ( + left: Stream.Stream, + right: Stream.Stream + ): Stream.Stream<[AL, AR], EL | ER, RL | RR> +} = dual( 2, - ( - self: Stream.Stream, - that: Stream.Stream - ): Stream.Stream<[A, A2], E2 | E, R2 | R> => pipe(self, crossWith(that, (a, a2) => [a, a2])) + ( + left: Stream.Stream, + right: Stream.Stream + ): Stream.Stream<[AL, AR], EL | ER, RL | RR> => pipe(left, crossWith(right, (a, a2) => [a, a2])) ) /** @internal */ -export const crossLeft = dual< - ( - that: Stream.Stream - ) => (self: Stream.Stream) => Stream.Stream, - ( - self: Stream.Stream, - that: Stream.Stream - ) => Stream.Stream ->( +export const crossLeft: { + ( + right: Stream.Stream + ): (left: Stream.Stream) => Stream.Stream + ( + left: Stream.Stream, + right: Stream.Stream + ): Stream.Stream +} = dual( 2, - ( - self: Stream.Stream, - that: Stream.Stream - ): Stream.Stream => pipe(self, crossWith(that, (a, _) => a)) + ( + left: Stream.Stream, + right: Stream.Stream + ): Stream.Stream => pipe(left, crossWith(right, (a, _) => a)) ) /** @internal */ -export const crossRight = dual< - ( - that: Stream.Stream - ) => (self: Stream.Stream) => Stream.Stream, - ( - self: Stream.Stream, - that: Stream.Stream - ) => Stream.Stream ->( +export const crossRight: { + ( + right: Stream.Stream + ): (left: Stream.Stream) => Stream.Stream + ( + left: Stream.Stream, + right: Stream.Stream + ): Stream.Stream +} = dual( 2, - ( - self: Stream.Stream, - that: Stream.Stream - ): Stream.Stream => flatMap(self, () => that) + ( + left: Stream.Stream, + right: Stream.Stream + ): Stream.Stream => flatMap(left, () => right) ) /** @internal */ -export const crossWith = dual< - ( - that: Stream.Stream, - f: (a: A, b: B) => C - ) => (self: Stream.Stream) => Stream.Stream, - ( - self: Stream.Stream, - that: Stream.Stream, - f: (a: A, b: B) => C - ) => Stream.Stream ->( +export const crossWith: { + ( + right: Stream.Stream, + f: (left: AL, right: AR) => A + ): (left: Stream.Stream) => Stream.Stream + ( + left: Stream.Stream, + right: Stream.Stream, + f: (left: AL, right: AR) => A + ): Stream.Stream +} = dual( 3, - ( - self: Stream.Stream, - that: Stream.Stream, - f: (a: A, b: B) => C - ): Stream.Stream => pipe(self, flatMap((a) => pipe(that, map((b) => f(a, b))))) + ( + left: Stream.Stream, + right: Stream.Stream, + f: (left: AL, right: AR) => A + ): Stream.Stream => pipe(left, flatMap((a) => pipe(right, map((b) => f(a, b))))) ) /** @internal */ @@ -7891,20 +7891,20 @@ export const zipAllWith = dual< ) /** @internal */ -export const zipLatest = dual< - ( - that: Stream.Stream - ) => (self: Stream.Stream) => Stream.Stream<[A, A2], E2 | E, R2 | R>, - ( - self: Stream.Stream, - that: Stream.Stream - ) => Stream.Stream<[A, A2], E2 | E, R2 | R> ->( +export const zipLatest: { + ( + right: Stream.Stream + ): (left: Stream.Stream) => Stream.Stream<[AL, AR], EL | ER, RL | RR> + ( + left: Stream.Stream, + right: Stream.Stream + ): Stream.Stream<[AL, AR], EL | ER, RL | RR> +} = dual( 2, - ( - self: Stream.Stream, - that: Stream.Stream - ): Stream.Stream<[A, A2], E2 | E, R2 | R> => pipe(self, zipLatestWith(that, (a, a2) => [a, a2])) + ( + left: Stream.Stream, + right: Stream.Stream + ): Stream.Stream<[AL, AR], EL | ER, RL | RR> => pipe(left, zipLatestWith(right, (a, a2) => [a, a2])) ) export const zipLatestAll = >>( @@ -7929,34 +7929,34 @@ export const zipLatestAll = ( - that: Stream.Stream, - f: (a: A, a2: A2) => A3 - ) => (self: Stream.Stream) => Stream.Stream, - ( - self: Stream.Stream, - that: Stream.Stream, - f: (a: A, a2: A2) => A3 - ) => Stream.Stream ->( +export const zipLatestWith: { + ( + right: Stream.Stream, + f: (left: AL, right: AR) => A + ): (left: Stream.Stream) => Stream.Stream + ( + left: Stream.Stream, + right: Stream.Stream, + f: (left: AL, right: AR) => A + ): Stream.Stream +} = dual( 3, - ( - self: Stream.Stream, - that: Stream.Stream, - f: (a: A, a2: A2) => A3 - ): Stream.Stream => { + ( + left: Stream.Stream, + right: Stream.Stream, + f: (left: AL, right: AR) => A + ): Stream.Stream => { const pullNonEmpty = <_R, _E, _A>( pull: Effect.Effect, Option.Option<_E>, _R> ): Effect.Effect, Option.Option<_E>, _R> => pipe(pull, Effect.flatMap((chunk) => Chunk.isEmpty(chunk) ? pullNonEmpty(pull) : Effect.succeed(chunk))) return pipe( - toPull(self), + toPull(left), Effect.map(pullNonEmpty), - Effect.zip(pipe(toPull(that), Effect.map(pullNonEmpty))), + Effect.zip(pipe(toPull(right), Effect.map(pullNonEmpty))), Effect.flatMap(([left, right]) => pipe( - fromEffectOption, Chunk.Chunk, boolean], E | E2, R | R2>( + fromEffectOption, Chunk.Chunk, boolean], EL | ER, RL | RR>( Effect.raceWith(left, right, { onSelfDone: (leftDone, rightFiber) => pipe( @@ -8020,23 +8020,23 @@ export const zipLatestWith = dual< ) /** @internal */ -export const zipLeft = dual< - ( - that: Stream.Stream - ) => (self: Stream.Stream) => Stream.Stream, - ( - self: Stream.Stream, - that: Stream.Stream - ) => Stream.Stream ->( +export const zipLeft: { + ( + right: Stream.Stream + ): (left: Stream.Stream) => Stream.Stream + ( + left: Stream.Stream, + right: Stream.Stream + ): Stream.Stream +} = dual( 2, - ( - self: Stream.Stream, - that: Stream.Stream - ): Stream.Stream => + ( + left: Stream.Stream, + right: Stream.Stream + ): Stream.Stream => pipe( - self, - zipWithChunks(that, (left, right) => { + left, + zipWithChunks(right, (left, right) => { if (left.length > right.length) { return [ pipe(left, Chunk.take(right.length)), @@ -8052,23 +8052,23 @@ export const zipLeft = dual< ) /** @internal */ -export const zipRight = dual< - ( - that: Stream.Stream - ) => (self: Stream.Stream) => Stream.Stream, - ( - self: Stream.Stream, - that: Stream.Stream - ) => Stream.Stream ->( +export const zipRight: { + ( + right: Stream.Stream + ): (left: Stream.Stream) => Stream.Stream + ( + left: Stream.Stream, + right: Stream.Stream + ): Stream.Stream +} = dual( 2, - ( - self: Stream.Stream, - that: Stream.Stream - ): Stream.Stream => + ( + left: Stream.Stream, + right: Stream.Stream + ): Stream.Stream => pipe( - self, - zipWithChunks(that, (left, right) => { + left, + zipWithChunks(right, (left, right) => { if (left.length > right.length) { return [ right, @@ -8084,24 +8084,24 @@ export const zipRight = dual< ) /** @internal */ -export const zipWith = dual< - ( - that: Stream.Stream, - f: (a: A, a2: A2) => A3 - ) => (self: Stream.Stream) => Stream.Stream, - ( - self: Stream.Stream, - that: Stream.Stream, - f: (a: A, a2: A2) => A3 - ) => Stream.Stream ->( +export const zipWith: { + ( + right: Stream.Stream, + f: (left: AL, right: AR) => A + ): (left: Stream.Stream) => Stream.Stream + ( + left: Stream.Stream, + right: Stream.Stream, + f: (left: AL, right: AR) => A + ): Stream.Stream +} = dual( 3, - ( - self: Stream.Stream, - that: Stream.Stream, - f: (a: A, a2: A2) => A3 - ): Stream.Stream => - pipe(self, zipWithChunks(that, (leftChunk, rightChunk) => zipChunks(leftChunk, rightChunk, f))) + ( + left: Stream.Stream, + right: Stream.Stream, + f: (left: AL, right: AR) => A + ): Stream.Stream => + pipe(left, zipWithChunks(right, (leftChunk, rightChunk) => zipChunks(leftChunk, rightChunk, f))) ) /** @internal */