-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Description
There is no way to clear a map in Go. You can write
for k := range m {
delete(m, k)
}
but that only works if m does not contain any key values that contain NaNs.
Based on the discussion in #55002, we suggest adding delete(m)
to the language to clear the map, always (even if it contains NaNs).
This is somewhat a reopening of #45328, which we closed because the loop was good enough, but we missed the earlier discussion in that issue of NaNs.
Adding delete(m) would then let us also add a similar mechanism in reflect.
We wouldn't need to add maps.Clear(m) since delete(m) is just as good.
mvdan, jimmyfrasche, jmank88, pierrre, guilhem and 117 moreawoo-civ, AlphaHot, deanveloper and SmartBoy84emilva, 0x5459, nightlyone, andig, remychantenay and 3 moreearthboundkid, DeedleFake, septemhill, caarlos0, diegostamigni and 6 more