Created
May 12, 2011 22:30
-
-
Save eyston/969602 to your computer and use it in GitHub Desktop.
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
// Scala's for comprehensions can be used like Haskell's do notation for monadic code, ie. its a compact way to string together computations sequentially. | |
val f = for { | |
a <- Future(10 / 2) // 10 / 2 = 5 | |
b <- Future(a + 1) // 5 + 1 = 6 | |
c <- Future(a - 1) // 5 - 1 = 4 | |
} yield b * c // 6 * 4 = 24 | |
val result = f.get() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment