Skip to content
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

Merged
merged 4 commits into from
Jan 29, 2019
Merged

Conversation

cb372
Copy link
Contributor

@cb372 cb372 commented Jan 12, 2019

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:

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)
}

Thank you for contributing to Cats!

This is a kind reminder to run sbt prePR and commit the changed files, if any, before submitting.

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)
}
```
LukaJCB
LukaJCB previously approved these changes Jan 12, 2019
@codecov-io
Copy link

codecov-io commented Jan 12, 2019

Codecov Report

Merging #2696 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
core/src/main/scala/cats/data/ContT.scala 100% <100%> (ø) ⬆️
core/src/main/scala/cats/data/Kleisli.scala 97.29% <0%> (+0.02%) ⬆️
core/src/main/scala/cats/syntax/apply.scala 57.14% <0%> (+32.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b4d1ad1...5f2f5e1. Read the comment docs.

@ceedubs
Copy link
Contributor

ceedubs commented Jan 13, 2019

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.

Copy link
Contributor

@kailuowang kailuowang left a 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.

@kailuowang kailuowang merged commit 2f65265 into typelevel:master Jan 29, 2019
@kailuowang kailuowang added this to the 2.0.0-M1 milestone Apr 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants