What is the meaning of <- clause in below code ?
Is it like an assignment ?
class Nested {
var filesHere = (new java.io.File(".")).listFiles()
def fileLines(file: java.io.File) =
scala.io.Source.fromFile(file).getLines().toList
def grep(pattern: String) =
for (
file <- filesHere
if (file.getName.endsWith(".scala"));
line <- fileLines(file)
if line.trim().matches(pattern)
) println(file + ": " + line.trim)
}
It’s not quite like an assignment: more like a for-each loop, but better. You can read about it here.
So this basically says, for each individual item
iin the collectionList(1,2,3,4), callprintln(i).