For review -- Comparator combinators (original) (raw)

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.

http://cr.openjdk.java.net/~henryjen/webrevs/8001667.0/ This allows things like: people.sort(Comparators.comparing(Person::getName)) Comparator 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 byLastFirst = Comparators.comparing(Person::getLastName, Person::getFirstName);

Or at least:

Comparitor byLastFirst = Comparators.comparing(Person::getLastName).compose(Person::getFirstName);

--



More information about the lambda-libs-spec-observers mailing list