Re:Streams in Java 8
by jargonjustin on Sunday February 09, 2014 @08:48PM
(#7208600)
Java's Comparator type is more general (you don't necessarily need to project the type for comparison) and an existing abstraction. It's not hard to introduce a combinator to transform the representation as a library, as in:
where `by` looks something like:
[ Parent
| on HN ]
Sure; and you'd have to import the thing that contains 'by'.
It's still ugly, and would prevent e.g. a radix sort being used when projecting an integer as the sort key, or American flag sort for strings.
It already exists in the API.
Your type Projection is a Function, and by is called comparing in interface Comparator.
so one can write: ``` contries.sorted(comparingInt(Country::getPopulation)). ... ```