Lambda it2 - split?
brian.goetz at oracle.com
Thu Sep 13 13:41:29 PDT 2012
There are a few ways to do this, depending on the shapes of your data.
One way is:
-> yields a Map<City, U> where U is the reduction
() -> new Averager(),
(avg, e) -> avg.updateWith(e))
.mapValues(avg -> avg.compute())
-> yields a Map<City, U>
which is probably more efficient.
On 9/13/2012 2:01 AM, Janda Martin wrote:
> I have newbie question. Does lambda streams support some kind of split operation?
> Virtual problem:
> Input: collection of cities
> List<City> cityList
> Output: average age for all people
> double avgAge
> Steps to solve:
> 1) Each city MAP to collection of people
> 2) Compute AVG over collection of people
> I know that I can
> - MAP input value exactly to another value
> - REDUCE collection to one value
> But can I?
> - SPLIT input value into 'stream' (not collection) of another values
> Thank you very much for answer
> PS Sorry for my bad English. I hope that you understand what I mean.
More information about the lambda-dev