Created
September 23, 2011 08:17
-
-
Save mads-hartmann/1236950 to your computer and use it in GitHub Desktop.
More statements in the for-comprehension wanted
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 op1 = Some("test") | |
val op2 = Some("test") | |
val l1 = List(1,2,3) | |
val l2 = List(1,2,3) | |
val product: Option[List[(Int,Int)]] = for { | |
t1 <- op1 | |
t2 <- op2 | |
} yield l1.flatMap { l => l2.map { l2 => (l,l2) }} | |
/* | |
It is my understanding that for-comprehensions are just | |
syntactic sugar for flatMap/filer so if I can write the | |
following it should be able to do as for-comprehension. Right? | |
*/ | |
op1.flatMap { t1 => | |
op2.flatMap { t2 => Some( | |
l1.flatMap { l => | |
l2.flatMap { l2 => | |
List((l,l2)) | |
}})}} |
teigen
commented
Sep 23, 2011
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment