Created
March 7, 2014 22:09
-
-
Save echeipesh/9421260 to your computer and use it in GitHub Desktop.
Reader Monad
This file contains 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
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