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

Skip to content

Conversation

@dag2ww
Copy link
Contributor

@dag2ww dag2ww commented Jul 10, 2019

Hi,
@iravid, other contrivutors

Please have a look at my changes and let me know your comments on these.

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.

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] =
Copy link
Member

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.

Copy link
Contributor Author

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 {
Copy link
Member

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.

Copy link
Contributor Author

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))
Copy link
Member

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?

Copy link
Contributor Author

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.

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 @dag2ww. This is going to be very useful!

@iravid
Copy link
Member

iravid commented Jul 12, 2019

The failed test is known to be flaky, so merging this.

[error]     x supervise fibers in supervised
[error]  TIMEOUT: 60 seconds (TestRuntime.scala:18)

@iravid iravid merged commit a6888b6 into zio:master Jul 12, 2019
@dag2ww
Copy link
Contributor Author

dag2ww commented Jul 12, 2019

Great! Really happy it's already into master :)
@iravid Thanks for review and hints!

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