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 ContravariantCartesian typeclass and for Tuple2 add Monad and FlatMap #1299

Merged
merged 10 commits into from
Aug 21, 2016

Conversation

johnynek
Copy link
Contributor

@johnynek johnynek commented Aug 19, 2016

These new instances should be isomorphic to WriterT[Id, A, B] instances, but there may be cases where you already have a tuple2 and want to use a monad.

This approach can be generalized to TupleN, but I am not sure it yet justifies code-gen or macros for this purpose.

Interestingly, one could make a Monad for a general case-class that is generic in at least the last parameter, but that may be going too far.

I also added Cartesian[Eq] to make the tests easier (otherwise I needed to plumb some new implicits everywhere).

@codecov-io
Copy link

codecov-io commented Aug 19, 2016

Codecov Report

Merging #1299 into master will decrease coverage by 0.03%.
The diff coverage is 90.24%.

@@            Coverage Diff             @@
##           master    #1299      +/-   ##
==========================================
- Coverage   90.66%   90.63%   -0.04%     
==========================================
  Files         236      237       +1     
  Lines        3684     3725      +41     
  Branches       56       58       +2     
==========================================
+ Hits         3340     3376      +36     
- Misses        344      349       +5
Impacted Files Coverage Δ
core/src/main/scala/cats/InvariantMonoidal.scala 77.77% <0%> (-15.56%)
core/src/main/scala/cats/Composed.scala 96% <100%> (+0.34%)
core/src/main/scala/cats/instances/tuple.scala 100% <100%> (ø)
...main/scala/cats/laws/discipline/FlatMapTests.scala 100% <100%> (ø)
...re/src/main/scala/cats/functor/Contravariant.scala 100% <100%> (ø)
core/src/main/scala/cats/Cartesian.scala 75% <100%> (+8.33%)
laws/src/main/scala/cats/laws/FlatMapLaws.scala 100% <100%> (ø)
...e/src/main/scala/cats/ContravariantCartesian.scala 83.33% <83.33%> (ø)
core/src/main/scala/cats/functor/Strong.scala 33.33% <0%> (-66.67%)
core/src/main/scala/cats/MonadFilter.scala 7.14% <0%> (-42.86%)
... and 12 more

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 8c1d3fa...cc3e6cb. Read the comment docs.

@johnynek johnynek changed the title Add Monad and FlatMap for Tuple2 Add ContravariantCartesian typeclass and for Tuple2 add Monad and FlatMap Aug 19, 2016
@erik-stripe
Copy link
Contributor

LGTM 👍

@@ -1,9 +1,12 @@
package cats
package instances

import data.Xor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either! :D

@adelbertc
Copy link
Contributor

#1289 is merged now - looks like this change doesn't have a merge conflict but I suspect if merged it will break the build :)

@johnynek
Copy link
Contributor Author

I'll update, get the coverage positive and try again.
On Fri, Aug 19, 2016 at 17:18 Adelbert Chang notifications@github.com
wrote:

#1289 #1289 is merged now - looks
like this change doesn't have a merge conflict but I suspect if merged it
will break the build :)


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#1299 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAEJdkJnOYfXU8t4J3veNKmlt92rlSq3ks5qhnIcgaJpZM4Jow6e
.

@johnynek
Copy link
Contributor Author

I think this is green now, except for the PR failing because of the Xor => Either. Since that is being reverted, this should be green after #1305 goes through.

@adelbertc
Copy link
Contributor

👍

@kailuowang
Copy link
Contributor

👍

@kailuowang kailuowang merged commit 21fb277 into master Aug 21, 2016
@kailuowang kailuowang deleted the oscar/tuple2monad branch March 15, 2017 15:07
@kailuowang kailuowang restored the oscar/tuple2monad branch March 15, 2017 15:07
@kailuowang kailuowang deleted the oscar/tuple2monad branch March 15, 2017 15:07
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.

7 participants