blob: 4e22ba801b11a3af6ee6e3b02172fec02f7a6534 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
module Util.List
( groupBy
) where
import Control.Arrow ((&&&))
import Data.Function (on)
import qualified Data.List as L
groupBy :: forall a b. (Ord b) => (a -> b) -> [a] -> [(b, [a])]
groupBy f =
map (f . head &&& id)
. L.groupBy ((==) `on` f)
. L.sortBy (compare `on` f)
|