Created
July 11, 2013 23:40
-
-
Save mindscratch/5980269 to your computer and use it in GitHub Desktop.
A nice example of using for/yield in Scala, copied from Learning Functional Programming without Growing a Neckbeard (http://www.youtube.com/watch?v=OOvL6QAxRK4)
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
| def goodPairings(pies: List[Pie], iceCreams: List[IceCream]): List(Serving[Pie, IceCream]) { | |
| for { | |
| p <- pies | |
| i <- iceCreams | |
| var serving = new Serving(p, i) | |
| if (serving.isGood) | |
| } yield { | |
| serving | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment