Skip to content

Instantly share code, notes, and snippets.

@fritschy
Created September 20, 2011 08:12
Show Gist options
  • Save fritschy/1228611 to your computer and use it in GitHub Desktop.
Save fritschy/1228611 to your computer and use it in GitHub Desktop.
sort -u for arbitrary haskell lists
module DecorateSortUniq where
import Data.List
decorateSortUniq :: Ord a => [a] -> [a]
decorateSortUniq = map snd . sortBy (\(a,_) (b,_)->compare a b) . uniq snd . sortBy (\(_,a) (_,b)->compare a b) . zip [0..]
where uniq f (x:y:xs) = if f x == f y then uniq f (x:xs) else x:uniq f (y:xs)
uniq _ (x:_) = [x]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment