18649, "bmcdonald3", "Implement a new remove method for set that returns the item removed", "2021-10-28T22:35:05Z"
Currently, set.remove()
returns a boolean value that represents whether or not the element was removed. It would be desirable to have another method that would return the removed element for cases where a user has overloaded the ==
operator on their own type.
Proposal 1: remove()
and drop()
-- sort of do what Python does
- Python has a
set.remove()
that throws if the element is not found and adrop()
that does nothing if the element is not found - this proposal is to change
set.remove()
to return the element found and add aset.drop()
that is equivalent to our currentset.remove()
Proposal 2: keep set.remove()
the same and add a more verbose method that returns
- the more verbose method could be something like
map.getAndRemove()
(though, this method halts, which we want to avoid here) - other ideas that came up:
fetchRemove()
,take()
- this more verbose method would also throw in the case where the object is not found