Proposal: more general unionWith for Data.Map

Henning Thielemann schlepptop at
Tue Jan 24 20:32:40 CET 2012

Milan Straka schrieb:

> If others agree, it is indeed simple to generalize type of
> unionWith[Key] from
>   unionWithKey :: Ord k => (k -> a -> a -> a) -> Map k a -> Map k a -> Map k a
> to
>   unionWithKey :: Ord k => (k -> a -> a -> Maybe a) -> Map k a -> Map k a -> Map k a
> These functions are used quite frequently in my opinion, so it will
> probably result in quite a lot of code breaks (unionWith (++) has to be
> changed to unionWith (\a b -> Just (a ++ b))).

Just for consistency with other "With" functions, the result of the
merger function should be 'a' not 'Maybe a'. Maybe 'unionUpdateWithKey'
or so would show the similarity to 'update'.

More information about the Libraries mailing list