Skip to content

Instantly share code, notes, and snippets.

@zainab-ali
Last active May 22, 2016 14:55
Show Gist options
  • Select an option

  • Save zainab-ali/fcc139585b10ce6651a79dd49a16fa3f to your computer and use it in GitHub Desktop.

Select an option

Save zainab-ali/fcc139585b10ce6651a79dd49a16fa3f to your computer and use it in GitHub Desktop.
Local functions on the Reader
//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