How do I map a Comparator

I have a comparator of type Comparator<Integer> and a function Function<Pair<Integer,?>,Integer> expressed as Pair::left (that returns an Integer).

I need to obtain a comparator of type Comparator<Pair<Integer,?>>.

If I wanted to simply map a function Function<T,U> to a resulting function Function<T,V> though a function Function<U,V> I could simply apply andThen() method like this:

Function<Integer, String> toBinary = Integer::toBinaryString;
Function<Pair<Integer, ?>, Integer> left = Pair::left;

var pairToBinary = left.andThen(toBinary); // has type Function<Pair<Integer, ?>, String>

Is it possible to obtain Comparator<Pair<Integer,?>> in a similar way?



Comments

Popular posts from this blog

I get wrong characters when retreiving the message body of an email using TIdIMAP4.UIDRetrieveTextPeek2()

How to drop the all the 1's in a correlation matrix

Today Walkin 14th-Sept