Created
February 17, 2015 17:51
-
-
Save everson/42b6124ec3a75205a804 to your computer and use it in GitHub Desktop.
Monadic Either
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
type Id = Int | |
def insertA():Either[Exception, Id] = {println("running A"); Right(1)} | |
def insertB(a: Id):Either[Exception, Id] = {println("running B with " + a); Left(new Exception("Oops"))} | |
def insertC(b: Id):Either[Exception, Id] = {println("running C with " + b); Right(3)} | |
for { | |
a <- insertA().right | |
b <- insertB(a).right | |
c <- insertC(b).right | |
} yield { | |
c | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment