I don't love `extract`, myself. I can see the motivation - extracting something generally means removing it without destroying it. But I worry that that's not salient enough to make the meaning clear. I dunno, maybe it's just that Data.Map already has "update", "alter" and "adjust", and I have no idea which is which - I don't think extract would be as bad as those, but it feels like in the same direction.
For the Maybe version, I'd suggest `deleteLookup`. Or at least something with both those words, but this combination seems to be what I'd expect given the existing `splitLookup`, `deleteFindMin` and `deleteFindMax`. "delete" seems to be the standard "remove something from the map" - the word "remove" isn't yet used, so I don't see any reason to introduce it. And "lookup" seems to be the standard name for "look something up using Maybe in case it's not there". (By contrast, "find" seems to be the standard name for "look something up and error if it's not there".)
For the default version, the only existing function I can see that takes a default is `findWithDefault`. (And this is the only use of "find" in the name of a function that doesn't error.) `deleteFindWithDefault` is a handful, but it would still be my suggestion.
`extract` is the name that I would suggest. I also agree with David that `pop` is a bit too confusing in a non-stack/queue data structure. If all languages named it pop, then it would be good argument for the name, but we don't need to copy python. The only thing that pyhon has that I wish we had in Haskell is the popularity ;)
+1 on the function itself from me, I've needed it multiple occasions.
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
LookupThenRemove seems like a more descriptive name. Though I guess I can see why pop has appeal.
I suggest you add a version for Data.Sequence combining lookup with deleteAt. I wanted that for something fairly recently.
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 mailing list
_______________________________________________
Libraries mailing list
_______________________________________________
Libraries mailing list
Libraries@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries