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

Created on 25 Jan 2018  ·  3Comments  ·  Source: golang/go

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.

FrozenDueToAge Proposal

Most helpful comment

This change wouldn't break existing code.

Yes, it would:

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

All 3 comments

This change wouldn't break existing code.

Yes, it would:

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

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

We can't change this signature.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bradfitz picture bradfitz  ·  3Comments

OneOfOne picture OneOfOne  ·  3Comments

enoodle picture enoodle  ·  3Comments

longzhizhi picture longzhizhi  ·  3Comments

myitcv picture myitcv  ·  3Comments