can any one helping me out to understand this code ...
object FileMatcher {
private def filesHere = (new java.io.File("C:/scalaTestcode")).listFiles
private def fileMatching(matcher : String => Boolean) =
{
for(file <- filesHere; if matcher(file.getName)) yield file
}
def filesEnding(query:String) =
fileMatching {_.endsWith(query) }
def filesContaining(query:String) =
fileMatching {_.contains(query)}
def fileRegex(query:String)=
fileMatching {_.matches(query)}
def main(args : Array[String])
{
(filesEnding(".scala").toArray).foreach(println)
}
}
This code working properly and as expected. But what I am trying to understand how filesEnding method with "_" working. I mean when I am calling from main I am calling with Query as a param in filesEnding method , that passes the function to the fileMatching with "_". , that "_" got filled up with some string in fileMatching, but when I am trying to fileMatching with any other String it is giving compilation error , if "_" in this case means any String , that should works with any String or by "_" we are telling scala compiler that , this will filled up by somewhere else/at implementation.
Any detail explanation will be appreciated.... Thanks a lot ...