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

longzhizhi picture longzhizhi  路  3Comments

bbodenmiller picture bbodenmiller  路  3Comments

bradfitz picture bradfitz  路  3Comments

dominikh picture dominikh  路  3Comments

ianlancetaylor picture ianlancetaylor  路  3Comments