Proposal: Add Data.List.sortNub and sortNubBy

Neil Mitchell ndmitchell at
Mon Mar 12 23:16:44 EDT 2007


I propose the addition of sortNub and sortNubBy.

Semantically sortNub = sort . nub

Practically, if you are doing both a sort and a nub, this can be implemented as:

sortNub = map head . group . sort

This is O(n log n) [time to sort], rather than O(n^2) [time to nub].

I have seen this around several times, often called snub. People have
also used snub to mean other things, snub itself has a meaning, and
sortNub is a more accurate name (following the concatMap tradition).

I personally have defined this function at least 25 times, I suspect
others have to. I can find 5 identical versions of it on google code
[1], and I know google code is lying because it's missing ones it
found earlier.




More information about the Libraries mailing list