Proposal for containers: Add 'pop' function to Data.Map

Martijn Bastiaan martijn at
Sun Dec 6 16:19:23 UTC 2020

Hi all,


   * Add `pop` and `popWithDefault` to `Data.Map` and `Data.IntMap`.
   * See for exact definition


   * 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:


Kind regards,
Martijn Bastiaan

More information about the Libraries mailing list