-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Change Set#delete to return Bool #9590
Change Set#delete to return Bool #9590
Conversation
It adds a simple and efficient way to know if the value was present or not.
Unless |
570976d
to
3859540
Compare
Co-authored-by: Ary Borenszweig <asterite@gmail.com>
Co-authored-by: Ary Borenszweig <asterite@gmail.com>
This reverts commit 22a0f40.
I think we should make But as usual, I think it's better to discuss these things in an issue, not in a PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API is good, the implementation not.
I have changed |
Co-authored-by: Sijawusz Pur Rahnama <sija@sija.pl>
Co-authored-by: Jonne Haß <me@jhass.eu>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed outdated specs wording, looks good otherwise
Co-authored-by: Jonne Haß <me@jhass.eu>
It adds a simple and efficient way to know if the value was present or not.
Design explanations
Having
Set#delete
returnsobject
ornil
is consistent with other#delete
methods in the stdlib:Hash#delete(object)
returns thevalue
ifobject
was present.Array#delete_at(index)
returns the removedvalue
at the given index, or raises an exception.However,
Deque#delete(object)
returns a boolean (maybe it would be better to return a count of deleted objects, but not the topic).Other options are:
Set#delete?(object) : Bool
to have parity withSet#add?
, but it can be considered redundantSet#delete(object)
return aBool
. Why not, but could be confusing:#add
does not return aBool
(but#add?
does)Side note: I don't think
Set#add
andSet#add?
are redundant, becauseSet#<<
is usingSet#add
, and one can easily chain object additions likeset << one << second << third
.Closes #9591