Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment