Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
val a = Array("apple", "banana", "orange")
for (e <- a) println(e)
for (e <- a) {
// imagine this requires multiple lines
val s = e.toUpperCase
println(s)
}
val newArray1 = for (e <- a) yield e.toUpperCase
println(newArray1)
val newArray2 = for (e <- a) yield {
// imagine this requires multiple lines
val s = e.toUpperCase
s
}
println(newArray2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment