Skip to content

Instantly share code, notes, and snippets.

@justjoheinz
Created October 10, 2014 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save justjoheinz/bcbaa4a4e69e61a1aa96 to your computer and use it in GitHub Desktop.
Save justjoheinz/bcbaa4a4e69e61a1aa96 to your computer and use it in GitHub Desktop.
Attempt to get the coproduct of natural transformations working.
trait NaturalTransformation[-F[_], +G[_]] {
self =>
def apply[A](fa: F[A]): G[A]
def compose[E[_]](f: E ~> F): E ~> G = new (E ~> G) {
def apply[A](ea: E[A]) = self(f(ea))
}
def or[H[_]](f: H ~> G): ({type f[x] = Coproduct[F, H, x]})#f ~> G =
new (({type f[x] = Coproduct[F, H, x]})#f ~> G) {
def apply[A](c: Coproduct[F, H, A]): G[A] = c.run match {
case -\/(fa) => self(fa)
case \/-(ha) => f(ha)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment