On Tue, Jan 19, 2021 at 10:02 PM burak serdar wrote:
>
> As a generic-function writer, I do not know if the argument will be an
> interface or a concrete type. I don't want to check if it is
> zero-value, I want to check if it is nil, because I don't want it to
> panic.
Other people in this threa
On Tue, Jan 19, 2021 at 7:06 PM burak serdar wrote:
> However, there is no way for P to check if x is nil. This does not compile:
>
> func P[T fmt.Stringer](x T) {
> if x!=nil {
> fmt.Println(x)
> }
> }
Is this doing what you want?
func P[T fmt.Stringer](x T) {
if fmt.St
On Tue, Jan 19, 2021 at 10:37 PM Ian Lance Taylor wrote:
>
> On Tue, Jan 19, 2021 at 8:02 PM burak serdar wrote:
> >
> > On Tue, Jan 19, 2021 at 8:38 PM Ian Lance Taylor wrote:
> > >
> > > On Tue, Jan 19, 2021 at 7:06 PM burak serdar wrote:
> > > >
> > > > In the following program, it is valid
On Tue, 2021-01-19 at 21:38 -0800, Ian Lance Taylor wrote:
> On Tue, Jan 19, 2021 at 8:41 PM Dan Kortschak
> wrote:
> >
> > Would that work for non-comparable types? Say the T has an
> > underlying
> > []int type, then the comparison is not against nil and you end up
> > with
> > a panic.
>
>
>
On Tue, Jan 19, 2021 at 8:41 PM Dan Kortschak wrote:
>
> On Tue, 2021-01-19 at 19:38 -0800, Ian Lance Taylor wrote:
> > On Tue, Jan 19, 2021 at 7:06 PM burak serdar
> > wrote:
> > >
> > > In the following program, it is valid to pass an interface to
> > > function P:
> > >
> > > func P[T fmt.Stri
On Tue, Jan 19, 2021 at 8:02 PM burak serdar wrote:
>
> On Tue, Jan 19, 2021 at 8:38 PM Ian Lance Taylor wrote:
> >
> > On Tue, Jan 19, 2021 at 7:06 PM burak serdar wrote:
> > >
> > > In the following program, it is valid to pass an interface to function P:
> > >
> > > func P[T fmt.Stringer](x T
On Tue, 2021-01-19 at 19:38 -0800, Ian Lance Taylor wrote:
> On Tue, Jan 19, 2021 at 7:06 PM burak serdar
> wrote:
> >
> > In the following program, it is valid to pass an interface to
> > function P:
> >
> > func P[T fmt.Stringer](x T) {
> > fmt.Println(x)
> > }
> >
> > func main() {
> >
On Tue, Jan 19, 2021 at 8:38 PM Ian Lance Taylor wrote:
>
> On Tue, Jan 19, 2021 at 7:06 PM burak serdar wrote:
> >
> > In the following program, it is valid to pass an interface to function P:
> >
> > func P[T fmt.Stringer](x T) {
> > fmt.Println(x)
> > }
> >
> > func main() {
> > var v f
On Tue, Jan 19, 2021 at 7:06 PM burak serdar wrote:
>
> In the following program, it is valid to pass an interface to function P:
>
> func P[T fmt.Stringer](x T) {
> fmt.Println(x)
> }
>
> func main() {
> var v fmt.Stringer
> P(v)
> }
>
> However, there is no way for P to check if x is ni
In the following program, it is valid to pass an interface to function P:
func P[T fmt.Stringer](x T) {
fmt.Println(x)
}
func main() {
var v fmt.Stringer
P(v)
}
However, there is no way for P to check if x is nil. This does not compile:
func P[T fmt.Stringer](x T) {
if x!=nil {
10 matches
Mail list logo