-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 foldRightDefer to Foldable #2772
Conversation
Thanks very much!
I lean towards option 1 unless having this method is urgent to you. |
Codecov Report
@@ Coverage Diff @@
## master #2772 +/- ##
==========================================
- Coverage 93.3% 93.28% -0.03%
==========================================
Files 376 376
Lines 7316 7323 +7
Branches 187 199 +12
==========================================
+ Hits 6826 6831 +5
- Misses 490 492 +2
Continue to review full report at Codecov.
|
I don't really mind either way. I just thought you would prefer something that could be merged immediately. I'll move the method to the typeclass. |
This reverts commit 9528be6.
Thanks very much! |
def loop(it: Iterator[A]): Eval[B] = | ||
Eval.defer(if (it.hasNext) f(it.next, loop(it)) else lb) | ||
def iterateRight[A, B](iterable: Iterable[A], lb: Eval[B])(f: (A, Eval[B]) => Eval[B]): Eval[B] = | ||
iterateRightDefer(iterable, lb)(f) |
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.
I would imagine inlining Eval.defer
will give a slight performance improvement since the jit can at best do this inlining later.
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.
@johnynek not sure I understand. Are you saying you would prefer the previous implementation explicitly calling Eval.defer
?
@denisrosca Do you mind merging master and changing the |
@travisbrown Don't mind. Hopefully I'll get to it this week. |
@denisrosca Would you mind if I do it now and push to this PR branch? We're aiming to publish 2.1.0-RC1 on Friday and it'd be great to get this in. |
I don't mind if you prefer to do it now. Thanks. |
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.
@denisrosca Thanks, done! I'm happy to see this merged when green. @johnynek?
Note, the addition of Iterable to Foldable in #2380 would allow us to use the iterateRightDefer method rather than the foldLeft implementation which I think will be more efficient (and I think allow short circuiting). |
Thanks for adding this BTW! |
This PR adds
foldRightDefer
toFoldable[F]
with the following signature:A new law to check the
foldRight <-> foldRightDefer
equivalence wheretype G[A] = Eval[A]
was also added to the test suite .To avoid binary incompatibilities, I added the function as a syntax enrichment for
Foldable[F]
andF[A] given a Foldable[F]
.Closes #2678