Proposal for containers: Add 'pop' function to Data.Map
Martijn Bastiaan
martijn at hmbastiaan.nl
Sun Dec 6 16:19:23 UTC 2020
Hi all,
Proposal:
* Add `pop` and `popWithDefault` to `Data.Map` and `Data.IntMap`.
* See https://github.com/haskell/containers/pull/757 for exact definition
Why:
* They're useful functions I expected to be in `Data.Map` and
`Data.IntMap`. (This might be influenced by the fact that
they're defined on Python's `dict`.)
* Their implementations (~ `updateLookupWithKey (\_ _ -> Nothing)`)
are harder to parse than a simple `pop`, which should help Haskell
codebases become a bit cleaner :).
* Their implementations are a bit non-obvious. My first instinct was
to write `(Map.lookup ..., Map.delete ...)`, which would have done
two traversals. Having "properly" implemented functions in the lib
would prevent people from writing their own suboptimal ones.
Details and implementation:
* https://github.com/haskell/containers/pull/757
Kind regards,
Martijn Bastiaan
More information about the Libraries
mailing list