Skip to content
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

proposal: sync: Map.Delete method should return bool, indicating if key was deleted or not #23547

Closed
lkarlslund opened this issue Jan 25, 2018 · 3 comments

Comments

@lkarlslund
Copy link

I propose that you expose a bool return variable in the sync map, changing it from:

func (m *Map) Delete(key interface{})

to:

func (m *Map) Delete(key interface{}) bool

The return value tells the caller whether the item was removed from the Map or not (true if key was in the map, false if the call did not change anything). It seems Map.Delete calls Map.delete internally, which already has the return data needed in some cases.

This change wouldn't break existing code.

@dominikh
Copy link
Member

This change wouldn't break existing code.

Yes, it would:

var deleteFn func(interface{}) = m.Delete

@bradfitz bradfitz changed the title sync.Map: Delete method should return bool, indicating if key was deleted or not proposal: sync: Map.Delete method should return bool, indicating if key was deleted or not Jan 25, 2018
@gopherbot gopherbot added this to the Proposal milestone Jan 25, 2018
@bradfitz
Copy link
Contributor

Yeah, we can't change any API signatures. See also: https://blog.merovius.de/2015/07/29/backwards-compatibility-in-go.html

@rsc
Copy link
Contributor

rsc commented Jan 29, 2018

We can't change this signature.

@rsc rsc closed this as completed Jan 29, 2018
@golang golang locked and limited conversation to collaborators Jan 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants