-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1299 from typelevel/oscar/tuple2monad
Add ContravariantCartesian typeclass and for Tuple2 add Monad and FlatMap
- Loading branch information
Showing
9 changed files
with
142 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cats | ||
|
||
import functor.Contravariant | ||
import simulacrum.typeclass | ||
|
||
/** | ||
* [[ContravariantCartesian]] is nothing more than something both contravariant | ||
* and Cartesian. It comes up enough to be useful, and composes well | ||
*/ | ||
@typeclass trait ContravariantCartesian[F[_]] extends Cartesian[F] with Contravariant[F] { self => | ||
override def composeFunctor[G[_]: Functor]: ContravariantCartesian[λ[α => F[G[α]]]] = | ||
new ComposedCartesian[F, G] { | ||
def F = self | ||
def G = Functor[G] | ||
} | ||
} | ||
|
||
object ContravariantCartesian extends KernelContravariantCartesianInstances | ||
|
||
private[cats] sealed trait KernelContravariantCartesianInstances { | ||
implicit val catsContravariantCartesianEq: ContravariantCartesian[Eq] = new ContravariantCartesian[Eq] { | ||
def contramap[A, B](fa: Eq[A])(fn: B => A): Eq[B] = fa.on(fn) | ||
def product[A, B](fa: Eq[A], fb: Eq[B]): Eq[(A, B)] = | ||
Eq.instance { (left, right) => fa.eqv(left._1, right._1) && fb.eqv(left._2, right._2) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters