Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@simpadjo
Copy link
Contributor

@simpadjo simpadjo commented May 29, 2020

#3711
Problems:

  1. Transducer >>> Sink : Sink composition is impossible now
  2. Sink is no longer contravariant in I
  3. Less than excellent type inference
  4. ZSink#contramap gone

Achievements: ZSink.head.flatmap(_ => Zsink.count) works!

@simpadjo simpadjo requested a review from iravid as a code owner May 29, 2020 08:32
@simpadjo simpadjo marked this pull request as draft May 29, 2020 08:36
@iravid
Copy link
Member

iravid commented Jun 1, 2020

This is coming along really nicely. Thank you for picking this up @simpadjo. With your help we will restore happiness to ZSink land ;-)

@simpadjo
Copy link
Contributor Author

simpadjo commented Jun 2, 2020

Deleted collectAllWhileWith for now.

foldChunksM is becoming problematic.

@simpadjo simpadjo marked this pull request as ready for review June 4, 2020 19:39
@simpadjo simpadjo changed the title Support leftovers in Sinks (wip) Support leftovers in Sinks Jun 4, 2020
@simpadjo simpadjo requested a review from iravid June 4, 2020 19:39
@simpadjo
Copy link
Contributor Author

simpadjo commented Jun 4, 2020

TODO:

  • ZStream#foldWhileManagedM should check cont condition after each element
  • restore ZSink#collectAllWhileWith
  • add more property-based tests to ensure chunking invariance of existing constructors/combinators

Copy link
Member

@iravid iravid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work @simpadjo. Thank you for working on this.

@simpadjo simpadjo requested a review from iravid June 4, 2020 22:49
@simpadjo simpadjo mentioned this pull request Jun 5, 2020
Copy link
Member

@iravid iravid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last comments! Good to merge afterwards 💪🏻

{
case Left(e) => ZIO.fail(e)
case Right(z) => restart.as(Chunk.single(z))
case (Left(e), _) => ZIO.fail(e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a weak spot. We have no contract that says that a transducer cannot be called after failing (and we shouldn't have such a contract). That means we're dropping leftovers inputs after failing.

How about placing these leftovers in a Ref that will be read on every push?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't disagree with you, although I can't come up with a testcase so far.
Seems that once you called stream.transduce(t) you can't see beyond the first error.

case (None, Some(z1)) => ZIO.succeedNow(RightDone(z1))
case (None, None) => ZIO.succeedNow(BothRunning)
case (Some((z, l)), Some((z1, l1))) => {
val minLeftover = if (l.length > l1.length) l1 else l
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's your reasoning behind using the minimum? I can see arguments for both choices, just wondering what you're thinking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider (s1.zipPar(s2)).zip(s3). We have two lineages of consumers: s1.zip(s3) and s2.zip(s3).
Returning the maximum means that one of the lineages consumes some elements twice.
Which is the most surprising behavior IMO.
We have consumers that ignore some of the input but no consumer processes an element twice (w/o explicitly being asked for).

Btw, what are the arguments for the opposite?

@iravid iravid merged commit 844314a into zio:master Jun 6, 2020
@iravid
Copy link
Member

iravid commented Jun 6, 2020

Thank you @simpadjo for your work on this 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants