Last active
March 16, 2016 18:27
-
-
Save andyscott/aff737669ad7855361cf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import cats.arrow.NaturalTransformation | |
| import cats.std.option._ | |
| import cats.syntax.cartesian._ | |
| implicit val opt2opt = NaturalTransformation.id[Option] | |
| implicit def id2F[F[_]: Applicative] = new (Id ~> F) { | |
| def apply[A](a: Id[A]): F[A] = Applicative[F].pure(a) | |
| } | |
| def foo[A: Order, F[_]: ~>[?[_], H], G[_]: ~>[?[_], H], H[_]: Applicative](f: F[A], g: G[A]) = { | |
| val first = implicitly[F ~> H].apply(f) | |
| val second = implicitly[G ~> H].apply(g) | |
| (first |@| second) map { Order[A].compare(_, _) } | |
| } | |
| class Bar[H[_]: Applicative] { | |
| def apply[A: Order, F[_]: ~>[?[_], H], G[_]: ~>[?[_], H]](f: F[A], g: G[A]) = { | |
| val first = implicitly[F ~> H].apply(f) | |
| val second = implicitly[G ~> H].apply(g) | |
| (first |@| second) map { Order[A].compare(_, _) } | |
| } | |
| } | |
| def bar[H[_]: Applicative] = new Bar[H] | |
| import cats.syntax.option._ | |
| import algebra.std.int._ | |
| val first: Option[Int] = 100.some | |
| val second: Id[Int] = 200 | |
| //val third = foo[Int, Option, Id, Option](first, second) | |
| val third = bar[Option].apply(first, second) | |
| println("first " + first) | |
| println("second " + second) | |
| println("third " + third) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment