2 ms·
How to implement flatMap(mapper) public final static <T,R> Gatherer<T, ?, R> flatMap(Function<? super T, ? extends Stream<R>> mapper){ return Gathe
by mjburgess 3y ago
How to implement flatMap(mapper)
public final static <T,R> Gatherer<T, ?, R> flatMap(Function<? super T, ? extends Stream<R>> mapper){
return Gatherer.of(
() -> (Void)null,
(nothing, element, downstream) -> {
try(Stream<? extends R> s = mapper.apply(element)) {
return s == null || s.sequential().allMatch(downstream::flush);
}
},
(l,r) -> l,
(nothing, downstream) -> {}
);
}
Better title: how scala won the war but lost every battle