Proposal: add alterLookupWithKey to Data.Map.Lazy (containers)

Станислав Черничкин schernichkin at gmail.com
Tue Apr 21 21:23:25 UTC 2015


Github issue: https://github.com/haskell/containers/issues/151

Summary: add alterLookupWithKey :: Ord k => (k -> Maybe a -> Maybe a) -> k
-> Map k a -> (Maybe a, Map k a) function to Data.Map.Lazy.

Details: implement alterLookupWithKey function which takes an update
function, key and map, allowing to insert, delete or update a value in a
Map and return updated map with a new value.

Motivations:

For insert/update/delete: same as for alter :: Ord k => (Maybe a -> Maybe
a) -> k -> Map k a -> Map k a - it allows to perform insert/update/delete
within single lookup.

For returning updated value: same as for *LookupWithKey functions - in case
of update we mind be interested in the updated value.

For a "key" parameter: hornestly, don't know. *LookupWithKey functions are
having (k -> .. ) -> k -> <a> -> Map k a -> (Maybe a, Map k a) signatures,
but I don't see any reason to pass the key to the update function, because
we always can capture the key in a closure if we whant to. The only reason
is to respect existent conventions. Since we already have
insertLookupWithKey and updateLookupWithKey functions it makes sence to
implement alterLookupWithKey in the same way.

-- 
Sincerely, Stanislav Chernichkin.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20150422/fc090dbc/attachment.html>


More information about the Libraries mailing list