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 some Contravariant instances #590

Closed
wants to merge 3 commits into from

Conversation

vikraman
Copy link
Contributor

This is an attempt to fix #579

@vikraman vikraman force-pushed the contravariant_instances branch from 64f672e to cbe070b Compare October 28, 2015 01:18
@vikraman
Copy link
Contributor Author

The ContravariantTests don't work because of the Eq requirement.

@codecov-io
Copy link

Current coverage is 75.83%

Merging #590 into master will decrease coverage by -0.09% as of a625f38

@@            master    #590   diff @@
======================================
  Files          159     159       
  Stmts         2185    2193     +8
  Branches        68      68       
  Methods          0       0       
======================================
+ Hit           1659    1663     +4
  Partial          0       0       
- Missed         526     530     +4

Review entire Coverage Diff as of a625f38

Powered by Codecov. Updated on successful CI builds.

@@ -21,6 +21,9 @@ final case class Kleisli[F[_], A, B](run: A => F[B]) { self =>
def map[C](f: B => C)(implicit F: Functor[F]): Kleisli[F, A, C] =
Kleisli(a => F.map(run(a))(f))

def contramap[C](f: C => B)(implicit F: Contravariant[F]): Kleisli[F, A, C] =
Kleisli(a => F.contramap(run(a))(f))

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the contramap that I would expect for Kleisli would be the local method that already exists on it. I think in practice the F in a Kleisli is often going to be covariant (not contravariant) in nature (Future, Task, Xor, etc), so I don't know how often this would be helpful. If you have some good examples of how you might use this, I'd definitely be interested in them.

Otherwise, should we get rid of this one and use local for the Contravariant instance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that does seem more useful. Is there a way to keep both the instances?

Copy link
Contributor

Choose a reason for hiding this comment

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

For simplicity, I'd be inclined to just keep the one until someone runs into a compelling use-case for the other.

@ceedubs
Copy link
Contributor

ceedubs commented Oct 31, 2015

Thanks a bunch for working on this, @vikraman!

@ceedubs
Copy link
Contributor

ceedubs commented Oct 31, 2015

For the missing Eq instances, I think you could add something like this to cats/laws/src/main/scala/cats/laws/discipline/Eq.scala:

  implicit def kleisliEq[F[_], A:Arbitrary, B](implicit FB: Eq[F[B]]): Eq[Kleisli[F, A, B]] =
    function1Eq[A, F[B]].on(_.run)

@ceedubs
Copy link
Contributor

ceedubs commented Nov 12, 2015

I believe this has been made obsolete by #626. I'm going to go ahead and close this. @vikraman please let me know if I'm missing something.

@ceedubs ceedubs closed this Nov 12, 2015
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.

Missing Contravariant instances
3 participants