Created
April 28, 2010 04:00
-
-
Save nathany/381711 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filesMatching(folder) { (file, dir) => // looks alot like a Ruby block | |
println(file + ": " + dir) // multiple statements | |
file.endsWith(query) && dir == false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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