DevoxxUK Lambdas Lab
Martijn Verburg
martijnverburg at gmail.com
Wed Apr 3 07:25:41 PDT 2013
Hi all,
On 3 April 2013 15:08, Richard Warburton <richard.warburton at gmail.com>wrote:
> >
> > If the problem was computing word frequency, the reason it is horrible
> > is not the API :)
> >
> > Map<String, Integer> m
> > = reader.lines()
> > .flatMap(s -> Arrays.stream(s.split(" ")))
> > .groupingBy(Functions.identity(),
> > reducing(s -> 1, Integer::sum)));
> >
>
> This is pretty much Identical to the code that Stuart produced, and its
> perfectly fine as far as addressing the question "Can you write an elegant
> solution to the problem using the streams api?" Unfortunately the
> important question is "Will blue collar Java developers be able to write a
> usable solution to the problem using the streams api?"
>
> My conclusion from running this lab is no. None of the people who attended
> realised that the use of the downstream collector for the values of the
> group was important in writing the code. I think this issue could be
> solved with better documentation pointing them to look at that method.
>
> I tested the hypothetical that this documentation was in place by pointing
> two attendees of the lab, who had successfully solved the easier exercises,
> in its direction. They still didn't produce "reducing(s -> 1,
> Integer::sum)". I'm honestly quite sceptical that people would make that
> leap. I don't think many developers when asked "produce something that
> collects the count of a list" Will intuitively go in the direction of:
>
> [ "dad", "dad", "dad" ] -> [1, 1, 1] -> 3
>
> Elsewhere in this thread there is a suggestion that a counting method
> should be provided. That's not only a good suggestion because counting
> things is a common method of collecting them, but its also a good
> suggestion to use this as an example, in the javadoc, in order to help
> developers build the intuition of this kind of Collector.
>
> I'm not quite as negative as Stephen on the issue, because when getting
> people to try out the streams API I think broadly people have picked things
> up easily and been able to comprehend the problems quickly. This is
> definitely one of the areas where they struggled a lot.
>
As one of the test subjects after the lab, I tend to agree, I certainly did
not instinctively move to reducing(s -> 1, Integer::sum), I instead wanted
a count method/function. That may say more about my lack of familiarity
with
Lambdas than anything, but hopefully it's another small data point.
Cheers,
Martijn
More information about the lambda-dev
mailing list