DevoxxUK Lambdas Lab
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Wed Apr 3 04:04:46 PDT 2013
Hi Stephen,
these problems are known, and are caused by the fact that the structural
most specific check only kicks in when the two candidates' SAM have
descriptors with the _same_ argument types. Unfortunately the signature
of those methods:
<T> comparing(ToLongFunction<? super T>)
<T>comparing(ToDoubleFunction<? super T>)
do not satisfy this property, as the argument types of the two
descriptor are _two_ different type-variables.
We are looking into ways to overcome this limitation.
Maurizio
On 03/04/13 11:34, Stephen Colebourne wrote:
> My experience (part 1):
>
> The afternoon did not start well, with some pretty basic inference problems:
> This works:
> ToIntFunction<String> ref = String::length;
> strs.sort(Comparators.comparing(ref).thenComparing(Comparators.naturalOrder()));
> This doesn’t work:
> strs.sort(Comparators.comparing(String::length).thenComparing(Comparators.naturalOrder()));
> Nor does this work:
> strs = strs.stream().sorted(Comparators.comparing(String::length)).sorted().collect(Collectors.toList());
>
> This works:
> strs.sort(Comparators.comparing((String s) ->
> s.length()).thenComparing(Comparators.naturalOrder()));
> This doesn’t work:
> strs.sort(Comparators.comparing(s ->
> s.length()).thenComparing(Comparators.naturalOrder()));
> Nor does this work:
> strs = strs.stream().sorted(Comparators.comparing(s ->
> s.length())).sorted().collect(Collectors.toList());
>
> In other words, both of the obvious (to me) ways to code this problem
> (sort by length then alphabetically) failed. If these can't be fixed,
> I'd be really worried about the usability of lambdas.
> Stephen
>
>
> On 3 April 2013 09:12, Richard Warburton <richard.warburton at gmail.com> wrote:
>> Last week at DevoxxUK we ran a brief lambdas hackday. People were
>> encouraged to focus on the collectors component of the API through setting
>> a few problems to solve. I appreciate its a bit late in the game as far as
>> API changes, but some of these issues are fixable through
>> documentation/improved compiler error changes rather than API changes.
>>
>> 1. No one complained about the move from “into(new ArrayList<Foo>());” ->
>> “collect(toList())” when you explained that the change had been made.
>> However, people didn’t naturally find Collectors.toList() and they did
>> express frustration around that. At least one request for an abbreviated
>> toList() method on a stream - more for findability/fluency reasons rather
>> than brevity of code.
>>
>> 2. ToIntFunction, ToDoubleFunction etc. are all usable with flatMap, but
>> the naming confused people as to why.
>>
>> 3. Several people requested a way to transform a boxed stream into an
>> unboxed stream. Its pretty easy to go the other way around, but there
>> didn’t seem to be any utility methods for making the boxed -> unboxed
>> transformation.
>>
>> 4. People found “groupingBy” to be a hard conceptual leap. We had set an
>> exercise where people were asked to count the frequency of words in a
>> document, in order to force them to use it.
>>
>> a. Quite a few people didn’t initially look for a function that collects a
>> stream into a map.
>>
>> b. When you suggest that they should look for that, they didn’t look for
>> something called “groupingBy”.
>>
>> c. They did get the concept once you bring up SQL. With hindsight I wished
>> I had enquired about how many people had used LINQ.
>>
>> d. People then didn’t grok that they needed to use the multiple argument
>> overload of groupingBy, with a reducingBy, in order to complete the task.
>> I suspect that this method needs more documentation examples in order to
>> be easily understandable by people.
>>
>> 5. People are beginning to get confused by old documentation on the
>> internet being out of date. I hadn’t seen this in previous hackdays. Even
>> an article in the latest Java Magazine is out of date due to the API moving
>> so much recently, and so is the official tutorial:
>> http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html.
>> Probably not a long term concern - but might be a concern for the first
>> few months.
>>
>> 6. If anyone else runs this kind of thing and they are a day-to-day eclipse
>> user, word of advice to make sure you know how to set the preferred JVM
>> location in netbeans and intellij before you run the event!
>>
>> Thanks to everyone that attended, and especially to Stuart Marks, Maurice
>> Naftalin, Graham Allan and John Oliver for helping out with running the lab.
>>
>> There’s a full link with code that people wrote and pasted at, and it also
>> contains some more comments by people:
>>
>> https://docs.google.com/document/d/1riMDt_JkAX74X30lHuOiSBjSxa7ifjxaynOA4LttOCk/edit
>>
>> regards,
>> *
>>
>> Richard Warburton
>>
>> http://insightfullogic.com
>> @RichardWarburto <http://twitter.com/richardwarburto>
>>
More information about the lambda-dev
mailing list