Last active
May 22, 2016 14:55
-
-
Save zainab-ali/fcc139585b10ce6651a79dd49a16fa3f to your computer and use it in GitHub Desktop.
Local functions on the Reader
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
| //local defined for GlobalEnv => Option[LocalEnv] | |
| def localOption[LocalEnv, GlobalEnv, A](r: Reader[LocalEnv, A])(f: GlobalEnv => Option[LocalEnv]): Reader[GlobalEnv, Option[A]] = | |
| Reader(globalEnv => f(globalEnv).map(r.run)) | |
| //generalization of the above in terms of Functors | |
| def localF[F[_], A, AA, B](r: Reader[A, B])(f: AA => F[A])(implicit F: Functor[F]): Reader[AA, F[B]] = | |
| Reader(aa => f(aa).map(r.run)) | |
| //generalization of the above in terms of Kleislis | |
| def localFK[F[_], A, AA, B](r: Kleisli[Id, A, B])(f: AA => F[A])(implicit F: Functor[F]): Kleisli[F, AA, B] = | |
| Kleisli(aa => f(aa).map(r.run)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment