Package org.nuxeo.common.stream
Class MapMultis
java.lang.Object
org.nuxeo.common.stream.MapMultis
- Since:
- 2025.12
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,R> BiConsumer<? super T, Consumer<R>> each(Function<T, ? extends Collection<R>> mapper) Returns aBiConsumerto use withStream.mapMulti(BiConsumer)in order to get a stream on aCollection.static <T,R> BiConsumer<? super T, Consumer<R>> eachIf(Function<T, ? extends Collection<R>> mapper, Predicate<R> predicate) Returns aBiConsumerto use withStream.mapMulti(BiConsumer)in order to get a stream on aCollectionthat passes the givenPredicate.static <T,R> BiConsumer<? super T, Consumer<R>> eachInstanceOf(Function<T, ? extends Collection<? super R>> mapper, Class<R> clazz) Returns aBiConsumerto use withStream.mapMulti(BiConsumer)in order to get a stream on aCollectionthat is of the givenClasstype.
-
Method Details
-
each
public static <T,R> BiConsumer<? super T,Consumer<R>> each(Function<T, ? extends Collection<R>> mapper) Returns aBiConsumerto use withStream.mapMulti(BiConsumer)in order to get a stream on aCollection. This is an equivalent of the flatMap approach:users.stream().map(User::getGroups).flatMap(List::stream); users.stream().mapMulti(MapMultis.each(User::getGroups));- Type Parameters:
T- the type of elements within the streamR- the type of elements within the collection- Parameters:
mapper- the mapping function to produce elements- Returns:
- a
BiConsumerto use with mapMulti
-
eachIf
public static <T,R> BiConsumer<? super T,Consumer<R>> eachIf(Function<T, ? extends Collection<R>> mapper, Predicate<R> predicate) Returns aBiConsumerto use withStream.mapMulti(BiConsumer)in order to get a stream on aCollectionthat passes the givenPredicate. This is an equivalent of the flatMap/filter approach:users.stream().map(User::getGroups).flatMap(List::stream).filter(Objects::nonNull); users.stream().mapMulti(MapMultis.eachIf(User::getGroups, Objects::nonNull));- Type Parameters:
T- the type of elements within the streamR- the type of elements within the collection- Parameters:
mapper- the mapping function to produce elementspredicate- the predicate that produced elements must pass- Returns:
- a
BiConsumerto use with mapMulti
-
eachInstanceOf
public static <T,R> BiConsumer<? super T,Consumer<R>> eachInstanceOf(Function<T, ? extends Collection<? super R>> mapper, Class<R> clazz) Returns aBiConsumerto use withStream.mapMulti(BiConsumer)in order to get a stream on aCollectionthat is of the givenClasstype.- Type Parameters:
T- the type of elements within the streamR- the type of elements within the collection- Parameters:
mapper- the mapping function to produce elementsclazz- the type of elements to keep- Returns:
- a
BiConsumerto use with mapMulti
-