I want to use Data.List.groupBy to group a list of tuples based on element equality snd.
I could do this:
groupBy (\l r -> snd l == snd r) listOfTuples
But this seems to me to be too big a template in the comparison function - especially since it can get a lot messier if I make a more complicated comparison. I would like to do something like:
groupBy (comparing snd) listOfTuples
but the signature of the comparison type is equal comparing :: (Ord a) => (b -> a) -> b -> b -> Ordering, so in this example it does not compile.
I could also:
groupBy (\l r -> (comparing snd l r) == EQ) listOfTuples
But this is not better than the first attempt. Is there a standard library solution for this problem before I roll?
source
share