For review -- Comparator combinators
David M. Lloyd
david.lloyd at redhat.com
Tue Nov 13 20:10:42 PST 2012
On 11/13/2012 09:41 PM, Brian Goetz wrote:
> The following is a webrev for proposed extension methods on Comparator
> (reverse and compose) as well as static combinator methods in
> Comparators for things like turning a T -> {Comparable,int,long,double}
> into a Comparator<T>.
>
> http://cr.openjdk.java.net/~henryjen/webrevs/8001667.0/
>
> This allows things like:
>
> people.sort(Comparators.comparing(Person::getName))
>
> Comparator<Person> byLastFirst
> = Comparators.comparing(Person::getLastName)
> .compose(Comparators.comparing(Person::getFirstName))
>
> Please review and comment.
I like the .compose notion in general, but wouldn't it be nice if you
could also, as a special case, do something like this:
Comparitor<Person> byLastFirst =
Comparators.comparing(Person::getLastName, Person::getFirstName);
Or at least:
Comparitor<Person> byLastFirst =
Comparators.comparing(Person::getLastName).compose(Person::getFirstName);
--
- DML
More information about the lambda-libs-spec-observers
mailing list