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

Martijn Bastiaan martijn at hmbastiaan.nl
Sun Dec 6 20:25:16 UTC 2020


I've taken a look, and it seems like a non-trivial change. For now I've 
added a version that simply traverses two times for Seq, to have API 
parity with Map/IntMap. If people are happy to accept pop/popWithDefault 
(be it with different names) I'll put in the work to make it do a single 
traversal for Seq too.

On 12/6/20 5:43 PM, David Feuer wrote:
> I suggest you add a version for Data.Sequence combining lookup with 
> deleteAt. I wanted that for something fairly recently.
>
> On Sun, Dec 6, 2020, 11:41 AM Martijn Bastiaan via Libraries 
> <libraries at haskell.org <mailto:libraries at haskell.org>> wrote:
>
>     Yeah, Python's `pop` made me call it `pop`. I had hoped to find other
>     examples, but Java, Rust, and Ruby don't seem to offer `pop`-like
>     functions for their (hash)maps.
>
>     On 12/6/20 5:29 PM, Tom Ellis wrote:
>     > On Sun, Dec 06, 2020 at 11:25:33AM -0500, David Feuer wrote:
>     >> The name pop makes me think of a stack. Is this use of the word
>     common?
>     > Python uses that name, which is why I'm familiar with it:
>     >
>     >>>> d = {'a': 1, 'b': 2}
>     >>>> d.pop('b')
>     > 2
>     >>>> d
>     > {'a': 1}
>     > _______________________________________________
>     > Libraries mailing list
>     > Libraries at haskell.org <mailto:Libraries at haskell.org>
>     > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>     _______________________________________________
>     Libraries mailing list
>     Libraries at haskell.org <mailto:Libraries at haskell.org>
>     http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20201206/9f688c2c/attachment.html>


More information about the Libraries mailing list