Class MapMultis

java.lang.Object
org.nuxeo.common.stream.MapMultis

public class MapMultis extends Object
Since:
2025.12
  • Method Details

    • each

      public static <T, R> BiConsumer<? super T,Consumer<R>> each(Function<T,? extends Collection<R>> mapper)
      Returns a BiConsumer to use with Stream.mapMulti(BiConsumer) in order to get a stream on a Collection. 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 stream
      R - the type of elements within the collection
      Parameters:
      mapper - the mapping function to produce elements
      Returns:
      a BiConsumer to use with mapMulti
    • eachIf

      public static <T, R> BiConsumer<? super T,Consumer<R>> eachIf(Function<T,? extends Collection<R>> mapper, Predicate<R> predicate)
      Returns a BiConsumer to use with Stream.mapMulti(BiConsumer) in order to get a stream on a Collection that passes the given Predicate. 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 stream
      R - the type of elements within the collection
      Parameters:
      mapper - the mapping function to produce elements
      predicate - the predicate that produced elements must pass
      Returns:
      a BiConsumer to 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 a BiConsumer to use with Stream.mapMulti(BiConsumer) in order to get a stream on a Collection that is of the given Class type.
      Type Parameters:
      T - the type of elements within the stream
      R - the type of elements within the collection
      Parameters:
      mapper - the mapping function to produce elements
      clazz - the type of elements to keep
      Returns:
      a BiConsumer to use with mapMulti