Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primitive Comparator.comparing(keyExtractor) #312

Open
barakugav opened this issue Jan 13, 2024 · 1 comment
Open

Primitive Comparator.comparing(keyExtractor) #312

barakugav opened this issue Jan 13, 2024 · 1 comment

Comments

@barakugav
Copy link
Contributor

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 :)

@vigna
Copy link
Owner

vigna commented Jan 13, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants