Created
December 12, 2016 18:33
-
-
Save Heimdell/0370cd22c4902727900e3371ab8f3091 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| {-# language TupleSections #-} | |
| import Control.Arrow ((&&&)) | |
| import Data.Function (on) | |
| import Data.List (groupBy, sortBy) | |
| import Data.Ord (comparing) | |
| f :: Ord k => [(v, [(k, x)])] -> [(k, [(v, x)])] | |
| f = map (fst.head &&& map snd) -- [[(k, (v, x))]] -> [(k, [(v, x)])] | |
| . groupBy ((==) `on` fst) -- [(k, (v, x))] -> [[(k, (v, x))]] | |
| . sortBy (comparing fst) -- [(k, (v, x))] -> [(k, (v, x))] | |
| . map (\(a, (b, c)) -> (b, (a, c))) -- [(v, (k, x))] -> [(k, (v, x))] | |
| . (uncurry (map . (,)) =<<) -- [(v, [(k, x)])] -> [(v, (k, x))] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment