Skip to content

Instantly share code, notes, and snippets.

@svmehta
Created July 14, 2012 19:12
Show Gist options
  • Save svmehta/3112810 to your computer and use it in GitHub Desktop.
Save svmehta/3112810 to your computer and use it in GitHub Desktop.
file walk
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