mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 13:02:07 +03:00
746521f8b2
Co-authored-by: Radosław Waśko <radoslaw.wasko@enso.org> Co-authored-by: Dmitry Bushev <bushevdv@gmail.com>
25 lines
655 B
Scala
25 lines
655 B
Scala
package src.main.scala.licenses
|
|
|
|
import java.nio.file.{Files, Path}
|
|
import java.util.stream.Collectors
|
|
|
|
import scala.collection.JavaConverters._
|
|
|
|
object FilesHelper {
|
|
|
|
/** A helper method that recursively traverses the directory structure at
|
|
* `root` and collects results of calling `action` on each encountered entry.
|
|
*
|
|
* The action is called for all kinds of entries that are encountered.
|
|
*/
|
|
def walk[R](root: Path)(action: Path => Seq[R]): Seq[R] = {
|
|
val stream = Files.walk(root)
|
|
try {
|
|
val list = stream.collect(Collectors.toList())
|
|
list.asScala.flatMap(action)
|
|
} finally {
|
|
stream.close()
|
|
}
|
|
}
|
|
}
|