Skip to content

Instantly share code, notes, and snippets.

@jedws
Created October 9, 2014 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jedws/05fca3c24f1a4cc6c8fc to your computer and use it in GitHub Desktop.
Save jedws/05fca3c24f1a4cc6c8fc to your computer and use it in GitHub Desktop.
lift a NaturalTransform into a type constructor that has a functor
import scalaz._
import scalaz.syntax.functor._
object LiftNaturalTransform {
def transform[F[_], G[_], M[_]: Functor, A](implicit nt: F ~> G): M[F[A]] => M[G[A]] =
_ map nt.apply
implicit class NaturalTransformSyntax[F[_], G[_]](f2g: F ~> G) {
def lift[M[_]: Functor] =
new NaturalTransformation[({ type λ[α] = M[F[α]] })#λ, ({ type λ[α] = M[G[α]] })#λ] {
def apply[A](mf: M[F[A]]): M[G[A]] =
Functor[M].apply(mf)(f2g)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment