Last active
September 22, 2018 10:14
-
-
Save ponkotuy/3e42f574f049a30c6322190f2e6a9ca2 to your computer and use it in GitHub Desktop.
Java NIO2をScalaでラップするやつ(findだけ)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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