Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zipLeft, zipRight methods (as addition to zip method) to ZStream and equivalent operators #1496

Closed
nicolasdasriaux opened this issue Aug 26, 2019 · 7 comments
Labels
enhancement New feature or request stream ZIO Stream

Comments

@nicolasdasriaux
Copy link

nicolasdasriaux commented Aug 26, 2019

On ZStream:

  • Add crossWith(f: (A, B) => C), equivalent to ls.flatMap(l => rs.map(f)
  • Add cross / <*>, equivalent to crossWith((_, _))
  • Add <*, equivalent to (l <*> r).map(_._1)
  • Add *>, equivalent to (l <*> r).map(_._2)
  • Add <&>, an alias for zip
  • Add zipLeft and <&, equivalent to (l <&> r).map(_._1)
  • Add zipRight and &>, equivalent to (l <&> r).map(_._2)
@iravid
Copy link
Member

iravid commented Aug 28, 2019

For consistency, the <*> variants should be based on flatMap, while the <&> should be based on zipWith.

If we were ultra-consistent, zipWith itself would have another name. But that's already been decided by other streaming libraries.

Also, I don't think we neeed &&&.

I'll update the description.

@jdegoes
Copy link
Member

jdegoes commented Aug 29, 2019

@iravid Don't we need zipWith and zipWithPar, and their variants (left/right)?

@nicolasdasriaux
Copy link
Author

nicolasdasriaux commented Aug 29, 2019

So would that imply something like that ?

Renaming

  • Rename current zipWith to zipParWith
  • Rename current zip to zipPar

zipParWith family

  • Add <&>, an alias for zipPar
  • Add zipParLeft and <&, equivalent to (l <&> r).map(_._1)
  • Add zipParRight and &>, equivalent to (l <&> r).map(_._2)

zipWith familly

  • Add zipWith
  • Add zip and <*> , equivalent to ls.flatMap(l => rs.map((l, _)))
  • Add zipLeft and <*, equivalent to (l <*> r).map(_._1)
  • Add zipRight and *>, equivalent to (l <*> r).map(_._2)

@iravid
Copy link
Member

iravid commented Aug 29, 2019

@jdegoes

We have ZStream#zipWith currently, which runs two streams in parallel. We don't have a named operator for ls.flatMap(l => rs.map(r => (l, r))).

@jdegoes @nicolasdasriaux

As I mentioned above, renaming the current zipWith to zipWithPar would be the most consistent. But keep in mind that this is inconsistent with the Scala collections library. Beyond that, most people I've worked with automatically reach for zipWith as the operator with the current semantics, and not zipParWith.

@jdegoes
Copy link
Member

jdegoes commented Aug 30, 2019

@iravid OK, it bothers me a bit but in cases where we only have one variant, we do omit the Par prefix. Of course we could flip it in this case, zipWithSeq for the other one, although crossWith would be better.

@iravid
Copy link
Member

iravid commented Sep 1, 2019

cross is a great idea. I will update the description.

@ghostdogpr
Copy link
Member

Closed by #1510

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request stream ZIO Stream
Projects
None yet
Development

No branches or pull requests

4 participants