[go-nuts] Re: generics: Zero value for any type parameter

2021-12-16 Thread Johan Bolmsjö
torsdag 16 december 2021 kl. 23:40:09 UTC+1 skrev Johan Bolmsjö: > > 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. > > I realized I should have read the generics

[go-nuts] Re: [generics] Zero value

2020-06-22 Thread brunokim . mc
Yes, they work, though a simpler solution is using 'var zero T' before the return statement. It'd be nice to have it inline, specially for multiple return values. Em segunda-feira, 22 de junho de 2020 10:13:43 UTC-3, Andrew Werner escreveu: > > In order to get a zero value, does the following

[go-nuts] Re: [generics] Zero value

2020-06-22 Thread Andrew Werner
In order to get a zero value, does the following work today? Is it acceptable? func GenericFunc(type T)() T { return func() (t T) { return t }() } This could also just be written like below but above I was trying to demonstrate how to make a zero value within another function. func

[go-nuts] Re: [generics] Zero value

2020-06-22 Thread Max
Types are not first-class in Go, thus T.someMethod() is somewhat an unusual syntax. The proposal to use 'T{}' to mean zero value of T breaks Go compatibility promise: if T is a map type or a slice type, 'T{}' already has a meaning: create a non-nil,

[go-nuts] Re: [generics] Zero value

2020-06-19 Thread Ivan Ivanyuk
What about something like int.CreateZeroValue(), or T.CreateZeroValue() and CreateZeroValueInterface? On Thursday, June 18, 2020 at 7:34:55 PM UTC+3, bruno...@gmail.com wrote: > > First, congratulations on the working compiler! Very cool to try out > generics in Go. > > I was experimenting