Created
September 3, 2015 22:43
-
-
Save trane/248bde43d840776c53a4 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
val a = Some(1) | |
val b = Some(2) | |
val c = Some(3) | |
for { | |
x <- a | |
y <- b | |
z <- c | |
} yield x + y + z // Some(6) | |
a.flatMap(x => // A => Option[B] | |
b.flatMap(y => // B => Option[C] | |
c.map(z => // C => D | |
x + y + z | |
) | |
) | |
) // Option[B] Some(6) | |
a.map(x => // A => B A => Option[_] | |
b.map(y => | |
c.map(z => | |
x + y + z) | |
) | |
) // Option[Option[Option[B]]] Some(Some(Some(6))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment