Hello,
I've been playing with the new generics support in 1.18beta 1 today. I've come across a situation a couple of times where it would be convenient to be able to conjure the zero value for a variable corresponding to a type parameter.
I've searched a bit for this to no avail. Understandably there is not much information on this topic in the wild yet. I've found a couple of issues in the issue tracker like returning '_' to represent the zero value but this does not seem to be implemented.
My workaround has been to create a dummy variable, zeroValue in the following example. I'm wondering if this is how to solve this problem or if there is a better way.
// Remove mapping associated with key from tree. Returns the removed value and
// true or the zero value of V and false if there was no mapping.
func (tree *Tree[K, V]) Remove(key K) (V, bool) {
var zeroValue V
if tree.root == nil {
return zeroValue, false
}
...
}