Skip to content

Instantly share code, notes, and snippets.

@ponkotuy
Last active September 22, 2018 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ponkotuy/3e42f574f049a30c6322190f2e6a9ca2 to your computer and use it in GitHub Desktop.
Save ponkotuy/3e42f574f049a30c6322190f2e6a9ca2 to your computer and use it in GitHub Desktop.
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