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
        }
    ...
}

-- 
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/74555573-9570-440e-94d8-c7f7f1fa8926n%40googlegroups.com.

Reply via email to