On Tue, 2020-11-10 at 20:28 -0800, 'Kilos' via golang-nuts wrote: > You cannot safely mutate a Go map while iterating over it with the > `range` operator.
This is not true, depending on your definition of "safely". See https://golang.org/ref/spec#For_statements "For statements with range clause" ``` 3. The iteration order over maps is not specified and is not guaranteed to be the same from one iteration to the next. If a map entry that has not yet been reached is removed during iteration, the corresponding iteration value will not be produced. If a map entry is created during iteration, that entry may be produced during the iteration or may be skipped. The choice may vary for each entry created and from one iteration to the next. If the map is nil, the number of iterations is 0. ``` So long as you take into account these caveats, mutating a map during a range will not corrupt the map or other data structure, and will cause your application to crash. -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b30864fe883e12005a71e656d40c3439cb695185.camel%40kortschak.io.