For review -- Comparator combinators

Brian Goetz brian.goetz at oracle.com
Tue Nov 13 19:41:34 PST 2012


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.



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