enso/project/src/main/scala/licenses/FilesHelper.scala
Ara Adkins 746521f8b2
Bump SBT and Scalafmt (#1203)
Co-authored-by: Radosław Waśko <radoslaw.wasko@enso.org>
Co-authored-by: Dmitry Bushev <bushevdv@gmail.com>
2020-10-22 16:12:28 +02:00

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()
}
}
}