Skip to content

Instantly share code, notes, and snippets.

@mindscratch
Created July 11, 2013 23:40
Show Gist options
  • Select an option

  • Save mindscratch/5980269 to your computer and use it in GitHub Desktop.

Select an option

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)
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