Created
April 29, 2018 21:50
-
-
Save strake/333dfd697a1ade4fea69e6c36536fc16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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