Brian Goetz brian.goetz at oracle.com
Fri Feb 8 07:47:17 PST 2013

OK, just to put it all down on "paper" where flatMap landed...are we OK 
with this?


public interface FlatMapper<T, U> {
     void explodeInto(T element, Consumer<U> sink);

     interface ToInt<T> {
         void explodeInto(T element, IntConsumer sink);

     interface ToLong<T> {
         void explodeInto(T element, LongConsumer sink);

     interface ToDouble<T> {
         void explodeInto(T element, DoubleConsumer sink);

     interface OfIntToInt {
         void explodeInto(int element, IntConsumer sink);

     interface OfLongToLong {
         void explodeInto(long element, LongConsumer sink);

     interface OfDoubleToDouble {
         void explodeInto(double element, DoubleConsumer sink);

In Stream:

     <R> Stream<R> flatMap(Function<T, Stream<? extends R>> mapper);

     <R> Stream<R> flatMap(FlatMapper<? super T, R> mapper);

     IntStream flatMap(FlatMapper.ToInt<? super T> mapper);
     LongStream flatMap(FlatMapper.ToLong<? super T> mapper);
     DoubleStream flatMap(FlatMapper.ToDouble<? super T> mapper);

In IntStream (similar for {Double,Long}Stream):

     IntStream flatMap(IntFunction<? extends IntStream> mapper);
     IntStream flatMap(FlatMapper.OfIntToInt mapper);

And Remi wants one more static helper method in FlatMap:

  public static <T, U> FlatMapper<T, U>
  explodeCollection(Function<? super T, ? extends Collection<? extends 
U>> function)

I think this wraps up the explosive section of our program?

On 2/6/2013 7:05 PM, Kevin Bourrillion wrote:
> On Wed, Feb 6, 2013 at 3:30 PM, Brian Goetz <brian.goetz at oracle.com
> <mailto:brian.goetz at oracle.com>> wrote:
>        Stream<U> flatMap(FlatMapper<T, U>)
>        Stream<U> flatMap(Function<T, Stream<U>>)
> To make sure I understand: would these two behave identically? Would
> they imaginably perform comparably?
>      foos.stream().flatMap((t, consumer) ->
> t.somethingThatGivesAStream().forEach(consumer))
>      foos.stream().flatMap(t -> t.somethingThatGivesAStream())
> Second question, why "FlatMapper.OfInt" here, but "IntSupplier" etc.
> elsewhere?
> --
> Kevin Bourrillion | Java Librarian | Google, Inc. |kevinb at google.com
> <mailto:kevinb at google.com>

More information about the lambda-libs-spec-observers mailing list