Skip to content

Instantly share code, notes, and snippets.

@strake
Created April 29, 2018 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save strake/333dfd697a1ade4fea69e6c36536fc16 to your computer and use it in GitHub Desktop.
Save strake/333dfd697a1ade4fea69e6c36536fc16 to your computer and use it in GitHub Desktop.
module OrdNub where
import qualified Data.Set as Set
ordNubOn :: Ord b => (a -> b) -> [a] -> [a]
ordNubOn f = go Set.empty
where go _ [] = []
go s (x:xs) | f_x `elem` s = go s xs
| otherwise = x : go (Set.insert f_x s) xs
where f_x = f x
ordNub :: Ord a => [a] -> [a]
ordNub = ordNubOn id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment