A focused look at Go's built-in `clear` function, introduced in Go 1.21. When called on a map, it deletes all entries leaving an empty map. When called on a slice, it zeroes out all elements without changing length or capacity. The post notes the behavioral asymmetry between maps and slices, explains why slice 'clearing' differs (since reslicing to zero length is trivial), and covers a workaround for using `clear` on arrays via a slice expression.
Table of contents
Clear6 Impressions