fastutil icon indicating copy to clipboard operation
fastutil copied to clipboard

Primitive Comparator.comparing(keyExtractor)

Open barakugav opened this issue 1 year ago • 1 comments

The standard java.util.Comparator provide few static methods to create a Comparator from an key extractor function:

static <T, U extends Comparable<U>> Comparator<T> comparing(Function<T, U> keyExtractor);
static <T, U extends Comparable<U>> Comparator<T> comparing(Function<T, U> keyExtractor, Comparator<U> keyComparator);
static <T> Comparator<T> comparingInt(ToIntFunction<T> keyExtractor);
static <T> Comparator<T> comparingLong(ToLongFunction<T> keyExtractor);
static <T> Comparator<T> comparingDouble(ToDoubleFunction<T> keyExtractor);

I find these functions very useful.

Will this be a nice additions to the primitive comparators in fastutil as well? For example in IntComparator. If so, I will be willing to add it :)

barakugav avatar Jan 13 '24 20:01 barakugav

Ok but you need to understand the macro system and write a generic implementation...

vigna avatar Jan 13 '24 21:01 vigna