Proposal: more general unionWith for Data.Map

John Meacham john at repetae.net
Wed Jan 25 00:08:45 CET 2012


I have needed this before

merge :: (a -> b -> Maybe c) -> (a -> Maybe c) -> (b -> Maybe c) ->
Map k a -> Map k b -> Map k c
mergeWithKey :: (k -> a -> b -> Maybe c) -> (k -> a -> Maybe c) ->
(k-> b -> Maybe c) -> Map k a -> Map k b -> Map k c

where the function arguments are
what to use when the key appears in both maps
what to use when the key appears in just the left map
what to use when the key appears in just the right map.

It seems like it would be the ultimate fully general fast map merging routine.

intersection = merge (Just . const) (const Nothing) (const Nothing)
union = merge (Just . const) Just Just
xor = merge ( const Nothing . const) Just Just

and so forth...

    John


    John



More information about the Libraries mailing list