Created
July 14, 2012 19:12
-
-
Save svmehta/3112810 to your computer and use it in GitHub Desktop.
file walk
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
def list(path: String): Future[Seq[File]] = { | |
val files = new java.io.File(path).listFiles.filter(a => !a.isHidden()) | |
Future.value(files.toSeq) | |
} | |
def walk(path: String): Future[Seq[File]] = { | |
list(path) flatMap { entries => | |
val children: Seq[Future[Seq[File]]] = entries map { entry => { | |
if (entry.isDirectory) | |
walk(entry.getPath()) | |
else | |
Future.value(Seq(entry)) | |
} | |
} | |
// Future.collect(children) flatMap (_.flatten) //compile error! | |
val a : Future[Seq[Seq[File]]] = Future.collect(children) | |
val b = a.map(_.flatten) | |
b | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment