clear(t) type parameter see below
If the argument type is a type parameter, all types in its type set must be maps or slices, and
clear
performs the operation corresponding to the actual type argument.
If the argument type (the type of the argument provided to clear) is a type parameter (is of type parameter type), all types in its type set (in the type set of the constraint corresponding to the type parameter) must be maps or slices, and clear performs the operation corresponding to the actual type argument (corresponding to the type of the actual type argument with which the type parameter was instantiated).
--
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 on the web visit https://groups.google.com/d/msgid/golang-nuts/CAN-HoCn99D-m71aJr3DRzCJvk_c7h8OhG2O4wPC-1Wd2ruEYNg%40mail.gmail.com.
So, if I get this right, clear on map will result in map length equals to zero, but clear on slice is only a value-zeroing operation and the slice length remains unchanged?
They seem like two different operations to me. I don't think that built-in clear function is necessary. It doesn't seem like the function has a good reason to be there.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/00e424f1-1a62-4183-8974-9a585960ce7dn%40googlegroups.com.
'make' allocates the required memory.
'len' returns the length.
'cap' returns the capacity.
The underlying implementation may be different, but the concept is the same. There is no issue with those.It is common for a collection to have methods such as 'Add', 'Delete', and 'Clear'. The common interpretation of clearing a collection means removing all items from the collection and setting its length to zero. Clear works like that with map, but it does differently with slice. I would not say replacing the values in a slice with the default values as clearing. Maybe you can call that zeroing, but that's not clearing. Many people would expect after calling 'Clear(slice)' then the slice length should be zero. That's why I think the function is incoherent.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/83de49c5-4624-4863-ab5b-fccc34565e32n%40googlegroups.com.