Created
December 28, 2010 16:28
-
-
Save debasishg/757389 to your computer and use it in GitHub Desktop.
Monads .. again
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 first = List(1, 2) | |
val next = List(8, 9) | |
for { | |
i <- first | |
j <- next | |
} | |
yield(i * j) | |
// gets converted to | |
first flatMap { | |
f => next map { | |
n => f * n | |
} | |
} | |
// List is a monad | |
// The 2 statements in the for comprehension act as generators for the lists | |
// Each pair generated is sequenced through the flatMap (which is Scala's bind) to generate the product |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment