Skip to content

Instantly share code, notes, and snippets.

@eyston
Created May 12, 2011 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eyston/969602 to your computer and use it in GitHub Desktop.
Save eyston/969602 to your computer and use it in GitHub Desktop.
// 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