Skip to content

Commit

Permalink
refactor(Stream): left/right parameters and generic names (#3306)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim <hello@timsmart.co>
  • Loading branch information
dilame and tim-smart authored Aug 23, 2024
1 parent ef3cc95 commit f960bf4
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 183 deletions.
5 changes: 5 additions & 0 deletions .changeset/stream-left-right.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Introduce left / right naming for Stream apis
98 changes: 49 additions & 49 deletions packages/effect/src/Stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1009,8 +1009,8 @@ export const concatAll: <A, E, R>(streams: Chunk.Chunk<Stream<A, E, R>>) => 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.
*
Expand All @@ -1034,29 +1034,29 @@ export const concatAll: <A, E, R>(streams: Chunk.Chunk<Stream<A, E, R>>) => Stre
* @category utils
*/
export const cross: {
<A2, E2, R2>(that: Stream<A2, E2, R2>): <A, E, R>(self: Stream<A, E, R>) => Stream<[A, A2], E2 | E, R2 | R>
<A, E, R, A2, E2, R2>(self: Stream<A, E, R>, that: Stream<A2, E2, R2>): Stream<[A, A2], E | E2, R | R2>
<AR, ER, RR>(right: Stream<AR, ER, RR>): <AL, EL, RL>(left: Stream<AL, EL, RL>) => Stream<[AL, AR], EL | ER, RL | RR>
<AL, ER, RR, AR, EL, RL>(left: Stream<AL, ER, RR>, right: Stream<AR, EL, RL>): 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.
*
* @since 2.0.0
* @category utils
*/
export const crossLeft: {
<A2, E2, R2>(that: Stream<A2, E2, R2>): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E2 | E, R2 | R>
<A, E, R, A2, E2, R2>(self: Stream<A, E, R>, that: Stream<A2, E2, R2>): Stream<A, E | E2, R | R2>
<AR, ER, RR>(right: Stream<AR, ER, RR>): <AL, EL, RL>(left: Stream<AL, EL, RL>) => Stream<AL, EL | ER, RL | RR>
<AL, EL, RL, AR, ER, RR>(left: Stream<AL, EL, RL>, right: Stream<AR, ER, RR>): Stream<AL, EL | ER, RL | RR>
} = 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.
Expand All @@ -1065,30 +1065,30 @@ export const crossLeft: {
* @category utils
*/
export const crossRight: {
<A2, E2, R2>(that: Stream<A2, E2, R2>): <A, E, R>(self: Stream<A, E, R>) => Stream<A2, E2 | E, R2 | R>
<A, E, R, A2, E2, R2>(self: Stream<A, E, R>, that: Stream<A2, E2, R2>): Stream<A2, E | E2, R | R2>
<AR, ER, RR>(right: Stream<AR, ER, RR>): <AL, EL, RL>(left: Stream<AL, EL, RL>) => Stream<AR, EL | ER, RL | RR>
<AL, EL, RL, AR, ER, RR>(left: Stream<AL, EL, RL>, right: Stream<AR, ER, RR>): Stream<AR, EL | ER, RL | RR>
} = 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.
*
* @since 2.0.0
* @category utils
*/
export const crossWith: {
<B, E2, R2, A, C>(
that: Stream<B, E2, R2>,
f: (a: A, b: B) => C
): <E, R>(self: Stream<A, E, R>) => Stream<C, E2 | E, R2 | R>
<A, E, R, B, E2, R2, C>(
self: Stream<A, E, R>,
that: Stream<B, E2, R2>,
f: (a: A, b: B) => C
): Stream<C, E | E2, R | R2>
<AR, ER, RR, AL, A>(
right: Stream<AR, ER, RR>,
f: (left: AL, right: AR) => A
): <EL, RL>(left: Stream<AL, EL, RL>) => Stream<A, EL | ER, RL | RR>
<AL, EL, RL, AR, ER, RR, A>(
left: Stream<AL, EL, RL>,
right: Stream<AR, ER, RR>,
f: (left: AL, right: AR) => A
): Stream<A, EL | ER, RL | RR>
} = internal.crossWith

/**
Expand Down Expand Up @@ -5519,8 +5519,8 @@ export const zipAllWith: {
* @category zipping
*/
export const zipLatest: {
<A2, E2, R2>(that: Stream<A2, E2, R2>): <A, E, R>(self: Stream<A, E, R>) => Stream<[A, A2], E2 | E, R2 | R>
<A, E, R, A2, E2, R2>(self: Stream<A, E, R>, that: Stream<A2, E2, R2>): Stream<[A, A2], E | E2, R | R2>
<AR, ER, RR>(right: Stream<AR, ER, RR>): <AL, EL, RL>(left: Stream<AL, EL, RL>) => Stream<[AL, AR], EL | ER, RL | RR>
<AL, EL, RL, AR, ER, RR>(left: Stream<AL, EL, RL>, right: Stream<AR, ER, RR>): Stream<[AL, AR], EL | ER, RL | RR>
} = internal.zipLatest

/**
Expand Down Expand Up @@ -5575,43 +5575,43 @@ export const zipLatestAll: <T extends ReadonlyArray<Stream<any, any, any>>>(
* @category zipping
*/
export const zipLatestWith: {
<A2, E2, R2, A, A3>(
that: Stream<A2, E2, R2>,
f: (a: A, a2: A2) => A3
): <E, R>(self: Stream<A, E, R>) => Stream<A3, E2 | E, R2 | R>
<A, E, R, A2, E2, R2, A3>(
self: Stream<A, E, R>,
that: Stream<A2, E2, R2>,
f: (a: A, a2: A2) => A3
): Stream<A3, E | E2, R | R2>
<AR, ER, RR, AL, A>(
right: Stream<AR, ER, RR>,
f: (left: AL, right: AR) => A
): <EL, RL>(left: Stream<AL, EL, RL>) => Stream<A, EL | ER, RL | RR>
<AL, EL, RL, AR, ER, RR, A>(
left: Stream<AL, EL, RL>,
right: Stream<AR, ER, RR>,
f: (left: AL, right: AR) => A
): Stream<A, EL | ER, RL | RR>
} = 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.
*
* @since 2.0.0
* @category zipping
*/
export const zipLeft: {
<A2, E2, R2>(that: Stream<A2, E2, R2>): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E2 | E, R2 | R>
<A, E, R, A2, E2, R2>(self: Stream<A, E, R>, that: Stream<A2, E2, R2>): Stream<A, E | E2, R | R2>
<AR, ER, RR>(right: Stream<AR, ER, RR>): <AL, EL, RL>(left: Stream<AL, EL, RL>) => Stream<AL, ER | EL, RR | RL>
<AL, EL, RL, AR, ER, RR>(left: Stream<AL, EL, RL>, right: Stream<AR, ER, RR>): Stream<AL, EL | ER, RL | RR>
} = 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.
*
* @since 2.0.0
* @category zipping
*/
export const zipRight: {
<A2, E2, R2>(that: Stream<A2, E2, R2>): <A, E, R>(self: Stream<A, E, R>) => Stream<A2, E2 | E, R2 | R>
<A, E, R, A2, E2, R2>(self: Stream<A, E, R>, that: Stream<A2, E2, R2>): Stream<A2, E | E2, R | R2>
<AR, ER, RR>(right: Stream<AR, ER, RR>): <AL, EL, RL>(left: Stream<AL, EL, RL>) => Stream<AR, ER | EL, RR | RL>
<AL, EL, RL, AR, ER, RR>(left: Stream<AL, EL, RL>, right: Stream<AR, ER, RR>): Stream<AR, EL | ER, RL | RR>
} = internal.zipRight

/**
Expand All @@ -5637,15 +5637,15 @@ export const zipRight: {
* @category zipping
*/
export const zipWith: {
<A2, E2, R2, A, A3>(
that: Stream<A2, E2, R2>,
f: (a: A, a2: A2) => A3
): <E, R>(self: Stream<A, E, R>) => Stream<A3, E2 | E, R2 | R>
<A, E, R, A2, E2, R2, A3>(
self: Stream<A, E, R>,
that: Stream<A2, E2, R2>,
f: (a: A, a2: A2) => A3
): Stream<A3, E | E2, R | R2>
<AR, ER, RR, AL, A>(
right: Stream<AR, ER, RR>,
f: (left: AL, right: AR) => A
): <EL, RL>(left: Stream<AL, EL, RL>) => Stream<A, EL | ER, RL | RR>
<AL, EL, RL, AR, ER, RR, A>(
left: Stream<AL, EL, RL>,
right: Stream<AR, ER, RR>,
f: (left: AL, right: AR) => A
): Stream<A, EL | ER, RL | RR>
} = internal.zipWith

/**
Expand Down
Loading

0 comments on commit f960bf4

Please sign in to comment.