Created
November 19, 2010 17:23
-
-
Save debasishg/706816 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// for comprehension | |
scala> for { | |
| l <- List(2,5,10) | |
| m <- List(8,10,11) | |
| } yield l * m | |
res17: List[Int] = List(16, 20, 22, 40, 50, 55, 80, 100, 110) | |
// map a pure function into applicatives | |
scala> List(8,10,11) <*> (List(2,5,10) map (((_: Int) * (_: Int)).curried)) | |
res18: List[Int] = List(16, 20, 22, 40, 50, 55, 80, 100, 110) | |
// lift-2 a pure function into an applicative | |
scala> List(2,5,10).<**>(List(8,10,11))(_ * _) | |
res21: List[Int] = List(16, 20, 22, 40, 50, 55, 80, 100, 110) |
Thanks a lot .. Looks nicer because of type inference .. I have still so much to learn in Scalaz :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or
Which generalizes nicely to higher arities.