Efficient way of mapping T to Map<X, Double>?

Brian Goetz brian.goetz at oracle.com
Wed Feb 13 18:06:02 PST 2013

Take a look at what happens when you do:

   groupingBy(Foo::getKey, mapping(Foo::getAmount, toIntStatistics());

This ends up functioning as a fused map-reduce.  You might find this a 
useful model.

On 2/13/2013 7:39 PM, Michael Nascimento wrote:
> Hi guys,
> What is an efficient way of, given a Stream<T>, obtain a Map<X,
> Double> (notice X is not the same type as T) given T is to be
> converted to the Double type by calling a method that returns double
> and is to be summed?
> So far what I have is:
> stream.collect(groupingReduce(d -> d.getX(), d -> d.getTotal(), Double::sum));
> but this results in some boxing I wish I could avoid.
> Regards,
> Michael

More information about the lambda-dev mailing list