sortingGroupBy :: (Ord b) => (a -> b)   -- ^ /discriminator function/
                          -> ([a] -> c) -- ^ /result function/
                          -> [a]        -- ^ a list
                          -> [(b, c)]   -- result of grouping and /result function/ application
sortingGroupBy f g = map (f . head &&& g)
                         . groupBy ((==) `on` f)
                         . sortBy (compare `on` f)
sortingGroupBy :: (Ord b) => (a -> b)   -- ^ /discriminator function/
                          -> ([a] -> c) -- ^ /result function/
                          -> [a]        -- ^ a list
                          -> [(b, c)]
sortingGroupBy f g = map (f . head &&& g)
                         . groupBy ((==) `on` f)
                         . sortBy (compare `on` f)
sortingGroupBy f g = map (f . head &&& g)
                         . groupBy ((==) `on` f)
                         . sortBy (compare `on` f)