-
Couldn't load subscription status.
- Fork 1.4k
Enhanced ZStream spaced to also emit schedule's output (#1120) #1162
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @dag2ww!
| override def fold[R2 <: R1 with Clock, E1 >: E, A1 >: Either[B, A], S]: Fold[R2, E1, A1, S] = | ||
| ZManaged.succeedLazy { (s, cont, f) => | ||
| def loop(s: S, sched: schedule.State, a: A): ZIO[R2, E1, S] = | ||
| def loop(s: S, schedSt: schedule.State, a: Either[B, A]): ZIO[R2, E1, S] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The loop doesn't need to take an Either[B, A] as it will only ever be called with an A.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, looks like it was too late for me to spot it ;P Thanks! Will change accordingly.
| if (decision.cont && cont(s)) | ||
| loop(s, decision.state, a).delay(decision.delay) | ||
| else IO.succeed(s) | ||
| f(s, a).zip(schedule.update(a.right.get, schedSt)).flatMap { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing a.right.get is unsafe, but it's actually unneeded here; once the definition of loop only uses an A, you won't need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I agree, however in this case we only put Left into Either upon stop, so no chance to get anything else than Right in the loop.
Anyway, over all - fully agree, Either not needed here at all :)
| .spaced(Schedule.recurs(1)) | ||
| .run(Sink.collectAll[Int]) | ||
| .map(_ must_=== List(1, 1, 2, 2, 3, 3)) | ||
| .map(_ must_=== List(1, 1, 2, 2, 2, 2, 3, 3, 2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test that uses a schedule with a different output type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea - this one requires (at least I required) some time to find out why such output sequence...
Will try to come up with some more meaningful test for this.
…dentified bug on end case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work @dag2ww. This is going to be very useful!
|
The failed test is known to be flaky, so merging this. |
|
Great! Really happy it's already into master :) |
Hi,
@iravid, other contrivutors
Please have a look at my changes and let me know your comments on these.