Skip to content

Instantly share code, notes, and snippets.

@echeipesh
Created March 7, 2014 22:09
Show Gist options
  • Save echeipesh/9421260 to your computer and use it in GitHub Desktop.
Save echeipesh/9421260 to your computer and use it in GitHub Desktop.
Reader Monad
case class Reader[C, A](g: C => A) {
def apply(c: C) = g(c)
def map[B](f: A => B): Reader[C, B] = {
Reader{ c => f(g(c)) }
}
def flatMap[B](f: A => Reader[C, B]): Reader[C, B] = {
Reader{ c => f(g(c))(c) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment