Maven
Şu satırı dahil ederiz
<dependency><groupId>io.vavr</groupId><artifactId>vavr</artifactId><version>0.10.4</version></dependency>
Örnek
Şöyle yaparız
var result = Stream.of("java.lang.String", "ch.frankel.blog.Dummy", "java.util.ArrayList") .map(CheckedFunction1.liftTry(Class::forName)) .map(Try::toEither) .partition(Either::isLeft) // 1 .map1(left -> left.map(Either::getLeft)) // 2 .map2(right -> right.map(Either::get)); // 3 result._1().forEach( it -> System.out.println("not found: " + it.getMessage())); // 4 result._2().forEach( it -> System.out.println("class: " + it.getName())); // 4
Açıklaması şöyle
1. Partition the Stream of Either in a tuple of two Stream2. Flatten the left stream from a Stream of Either to a Stream of Throwable3. Flatten the right stream from a Stream of Either to a Stream of Class4. Do whatever we want
Hiç yorum yok:
Yorum Gönder