delete()/clear() to return boolean

108 views
Skip to first unread message

Alexander Shopov

unread,
Nov 30, 2025, 3:43:52 PM (3 days ago) Nov 30
to golang-nuts
Hi all,

Go 1.26 is expected early next year and it contains a change in the semantics of the built-in function `new`. Apart from taking a type, new now can take a literal and return a pointer to a value represented by the literal.

Has there been a discussion (ever) of changing the behavior of the `delete`/`clear` functions so that they can return a boolean indicating whether they actually deleted something?

In some cases it is nice to have an indication whether these functions actually deleted anything. 

One can achieve this with an additional line of checking whether the values they act upon contain a particular value (for delete) or any value (for clear). But in a similar way new with literal also saves a single line.

Does that make sense? Is there any interest in such a feature?

Kind regards:
al_shopov

Sean Liao

unread,
Nov 30, 2025, 4:56:56 PM (3 days ago) Nov 30
to golang-nuts
https://go.dev/issue/41130

- sean
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/CAP6f5MkTiDsq_81r5JbUOkh5g0r74%2B8W2KJGY6BBORvmneuMbA%40mail.gmail.com.

Jeremy French

unread,
Dec 1, 2025, 6:07:56 AM (2 days ago) Dec 1
to golang-nuts
And chasing that thread leads to this explanation from someone who was in the room when the decision was made: 

Reply all
Reply to author
Forward
0 new messages