Skip to content

Map.unionWithMaybe

for Data.Map, I needed a "unionWithMaybe" function for my sparse system of linear equations (unionWithMaybe :: Ord k => (a -> a -> Maybe a) -> Map k a -> Map k a -> Map k a). My usage: (.+.) = Map.unionWithMaybe (\a b->case a+b of {0->Nothing;s->Just s}) (I do not think Map.unionWithMaybe can be expressed in terms of other functions without loosing performance, so I recon it would be a nice addition to the library.)

I built this function myself by modifying the Data.Map implementation, but it would be nice to see it in the official version of Data.Map. Here is the file including the modifications I made to it. Feel free to use it, I will agree to whatever license you need to make it public.

(PS: this is the first time I return modified source code to the maintainer, feel free to instruct me on how to do this in the future.)

Trac metadata
Trac field Value
Version 7.6.3
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/base
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information