Skip to content

Instantly share code, notes, and snippets.

@nathany
Created April 28, 2010 04:00
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 nathany/381711 to your computer and use it in GitHub Desktop.
Save nathany/381711 to your computer and use it in GitHub Desktop.
filesMatching(folder) { (file, dir) => // looks alot like a Ruby block
println(file + ": " + dir) // multiple statements
file.endsWith(query) && dir == false
}
// experimenting with currying, though not actually a great way to do this
object FileMatcher {
def fileList(folder: String) = (new java.io.File(folder)).listFiles
def filesMatching(folder: String)(matcher: (String, Boolean) => Boolean) = {
for (file <- fileList(folder); if matcher(file.getName, file.isDirectory))
yield file
}
def filesEnding(folder:String, query: String) = {
filesMatching(folder) { (file, dir) => // looks alot like a Ruby block
println(file + ": " + dir) // multiple statements
file.endsWith(query) && dir == false
}
}
def filesContaining(folder:String, query: String) = {
filesMatching(folder) { _.contains(query) && _ == false } // placeholders
}
}
// script
for(file <- FileMatcher.filesEnding(".", ".scala"))
println(file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment