Skip to content

Instantly share code, notes, and snippets.

@ponkotuy ponkotuy/Files.scala
Last active Sep 22, 2018

Embed
What would you like to do?
Java NIO2をScalaでラップするやつ(findだけ)
import java.nio.file.{Path, Files => JFiles}
import java.nio.file.attribute.BasicFileAttributes
import java.util.function.{BiPredicate, Consumer}
import scala.collection.JavaConverters._
object Files {
import JFunction._
def find(path: Path, depth: Int = Int.MaxValue)(matcher: (Path, BasicFileAttributes) => Boolean): Iterator[Path] =
JFiles.find(path, depth, matcher.asJava).iterator().asScala
}
object JFunction {
implicit class BiPredicateAsJava[A, B](val biPred: (A, B) => Boolean) {
def asJava: BiPredicate[A, B] = new BiPredicate[A, B] {
override def test(a: A, b: B): Boolean = biPred(a, b)
}
}
implicit class ConsumerAsJava[A](val consumer: A => Unit) {
def asJava: Consumer[A] = new Consumer[A] {
override def accept(a: A): Unit = consumer(a)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.