Last active
May 3, 2019 09:53
-
-
Save slouc/65e2e22d8f94e2d165121e36e18545a5 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._ | |
abstract class Yoneda[F[_]: Functor, A] { self => | |
def apply[B](f: A => B): F[B] | |
def run: F[A] = apply(identity) | |
def map[B](f: A => B): Yoneda[F, B] = new Yoneda[F, B] { | |
def apply[C](g: B => C): F[C] = self.apply(f andThen g) | |
} | |
} | |
def toYoneda[F[_]: Functor, A](fa: F[A]): Yoneda[F, A] = | |
new Yoneda[F, A] { | |
override def apply[B](f: (A) => B): F[B] = Functor[F].map(fa)(f) | |
} | |
def fromYoneda[F[_], A](y: Yoneda[F, A]): F[A] = y.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment