Re: [go-nuts] zero value for generic types?

2022-04-21 Thread roger peppe
On Wed, 20 Apr 2022 at 23:29, Arthur Comte wrote: > Actually, even with proper error handling, I still need to return a value. > In some functions I can just return a variable that was defined in the > function, but that is not always available. In those cases, the only > solution I've found is t

Re: [go-nuts] zero value for generic types?

2022-04-20 Thread Ian Lance Taylor
On Wed, Apr 20, 2022 at 3:30 PM Arthur Comte wrote: > > Actually, even with proper error handling, I still need to return a value. In > some functions I can just return a variable that was defined in the function, > but that is not always available. In those cases, the only solution I've > foun

Re: [go-nuts] zero value for generic types?

2022-04-20 Thread Arthur Comte
Actually, even with proper error handling, I still need to return a value. In some functions I can just return a variable that was defined in the function, but that is not always available. In those cases, the only solution I've found is to use `*new(E)`, which seems plain terrible. Is there an alt

[go-nuts] zero value for generic types?

2022-04-20 Thread Arthur Comte
Hi! I was trying the following code, but it does not compile. How can I check if a generic value is its zero value. More broadly, can you explain where this issue comes from? ```go type MemoryRepository[E identifiable.Identifiable] struct { elements []E } func (repo MemoryRepository[E]) Find(I