-
Notifications
You must be signed in to change notification settings - Fork 425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement a method similar to the Python set.pop()
#18652
Comments
I'm good with this functionality, but am not a fan of In the meeting today, I proposed an argument-less I couldn't find an equivalent of pop()/removeArbitrary()/removeElement() in Rust, which surprised me slightly. But they do have a drain() method which seems to be an iterator that removes elements and yields them. So if we thought that the main use of pop() was a work-queue type of thing, we could potentially take that approach instead (though I don't think it would support the pattern Andrew was talking about in which we might simultaneously be adding things back into the set as we drained it... or at least, that feels scary / potentially expensive to me, at least in a parallel setting). Why do I mention this? In part because the name |
I'm okay with |
I don't think I like this approach since, as you mention, it doesn't apply to the only real use-case that we were able to come up with in the original discussion here, so it feels almost like adding something without a very compelling reason to do so, which makes me think this may be a better after 2.0 effort. Returning to the original question of adding Python's Do either @lydia-duncan or @bradcray have an opinion on if this should be a pre- or post-2.0 effort? |
I was viewing it as a post-2.0 effort, yeah |
It would not surprise me if someone will end up wanting it prior to 2.0 (in which case we should add it), but I agree that we don't need to solve it in order to declare 2.0. |
Python supports a
set.pop()
method which removes and returns a random element from the set. This could be valuable when trying to use your set as an unordered queue and other cases.Python pop: https://www.w3schools.com/python/ref_set_pop.asp
The text was updated successfully, but these errors were encountered: