-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
collect ::
  (Ord b) =>
  [a] ->
  (a -> b) ->
  (a -> c) ->
  M.Map b [c]
collect as mkKey mkVal = foldr step M.empty as
  where
    step x acc = MS.insertWith (++) (mkKey x) ([mkVal x]) acc

-------------------------------------------------------------------------------
collect ::
  (Ord b) =>
  [a] ->
  (a -> b) ->
  (a -> c) ->
  M.Map b [c]
collect as mkKey mkVal = foldr step M.empty as
  where
    step x acc = MS.insertWith (++) (mkKey x) ([mkVal x]) acc

-------------------------------------------------------------------------------
collect as mkKey mkVal = foldr step M.empty as
  where
    step x acc = MS.insertWith (++) (mkKey x) ([mkVal x]) acc

-------------------------------------------------------------------------------