-
-
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 a defer
factory method to ContT
#2696
Conversation
Similar to the existing `pure` function, but evaluation of the argument is deferred. This is useful for building a computation which calls its continuation as the final step. Instead of writing: ``` ContT.apply { next => val x = foo() val y = bar(x) val z = baz(y) next(z) } ``` you can write: ``` ContT.defer { val x = foo() val y = bar(x) baz(y) } ```
Codecov Report
@@ Coverage Diff @@
## master #2696 +/- ##
==========================================
+ Coverage 95.15% 95.16% +<.01%
==========================================
Files 365 365
Lines 6774 6780 +6
Branches 297 296 -1
==========================================
+ Hits 6446 6452 +6
Misses 328 328
Continue to review full report at Codecov.
|
Thanks @cb372! Would you be willing to add a ScalaDoc description of the method and a unit test or two? One unit test that I think would be good is one that checks that the argument isn't eagerly evaluated. |
There's no need to use a DeferCont here.
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.
Thanks, sorry about the delay. somehow I missed this.
As suggested in #2677.
Similar to the existing
pure
function, but evaluation of the argument is deferred.This is useful for building a computation which calls its continuation as the final step. Instead of writing:
you can write:
Thank you for contributing to Cats!
This is a kind reminder to run
sbt prePR
and commit the changed files, if any, before submitting.