Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created February 5, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shigemk2/8cf6351e482e3a50804a to your computer and use it in GitHub Desktop.
Save shigemk2/8cf6351e482e3a50804a to your computer and use it in GitHub Desktop.
val names = Array("chris", "ed", "maurice")
println(names(0))
val capNames = for (e <- names) yield e.capitalize
println(capNames(0))
val lengths = for (e <- names) yield {
// imagine that this required multiple lines of code
e.length
}
println(lengths(0))
var fruits = scala.collection.mutable.ArrayBuffer[String]()
fruits += "apple"
fruits += "banana"
fruits += "orange"
println(fruits(0))
val out = for (e <- fruits) yield e.toUpperCase
println(out(0))
var fruits2 = "apple" :: "banana" :: "orange" :: Nil
println(fruits2(0))
var out2 = for (e <- fruits2) yield e.toUpperCase
println(out2(0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment