Last active
November 18, 2017 12:30
-
-
Save tjheslin1/147c5eab62d88c8184cd661b77a48858 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
// Taken from Essential Scala by Noel Welsh and Dave Gurnell | |
for { | |
a <- getFirstNumber // getFirstNumber returns Option[Int] | |
b <- getSecondNumber // getSecondNumber returns Option[Int] | |
} yield a + b | |
// The final result is an Option[Int]---the result of | |
// applying `+` to `a` and `b` if both values are present | |
for { | |
a <- getFirstNumbers // getFirstNumbers returns Seq[Int] | |
b <- getSecondNumbers // getSecondNumbers returns Seq[Int] | |
} yield a + b | |
// The final result is a Seq[Int]---the results of | |
// applying `+` to all combinations of `a` and `b` | |
for { | |
a <- getFirstNumber // getFirstNumber returns Future[Int] | |
b <- getSecondNumber // getSecondNumber returns Future[Int] | |
} yield a + b | |
// The final result is a Future[Int]---a data structure | |
// that will eventually allow us to access the result of |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment