Skip to content

Instantly share code, notes, and snippets.

@strake strake/OrdNub.hs
Created Apr 29, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.