Grzegorz Piwowarek
@pivovarit
Optional#get
http://mail.openjdk.java.net/pipermail/core-libs-dev/2016-April/040484.html
@Deprecated?
Optional#ifPresentOrElse
findById(42) .ifPresentOrElse( this::log, this::logError);
Optional#or
Optional<User> user = findById(42).or(() -> findByName("Adam"))
Optional#stream
list.stream() .filter(Optional::isPresent) .map(Optional::get) .collect(toList());
list.stream() .flatMap(Optional::stream) .collect(toList());
Stream#ofNullable
Stream.of("Maria", "Robert", "Krzysztof") .flatMap(n -> ofNullable(findByName(n))) .findAny()
Stream#takeWhile/dropWhile
IntStream.iterate(0, i -> 2 * i) .takeWhile(i -> i < 42) .forEach(...)
IntStream.iterate(0, i -> 2 * i) .dropWhile(i -> i < 42) .forEach(...)
Stream#iterate
Stream.iterate(1, i -> i <= 42, i -> 2 * i)
Collectors#filtering
.collect( groupingBy(User::getName, filtering(user -> user.getValue() > 15_000, toList())));
Collectors#flatmapping
.collect( groupingBy(User::getName, flatMapping(User::getChildren, toList())));
Thank you!
By Grzegorz Piwowarek