Re: [go-nuts] Is there a way to eliminate the code repetition in the code?

2022-03-20 Thread Ian Lance Taylor
I don't think so.

https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#no-way-to-express-convertibility

Ian

-- 
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/CAOyqgcVL9b0zkBQMYs0Dc9O1omOquEfnEHAww7X7NuUOFo6XeA%40mail.gmail.com.


[go-nuts] Is there a way to eliminate the code repetition in the code?

2022-03-20 Thread tapi...@gmail.com


package main

type A interface {
Ma()
}

type B interface {
Mb()
}

type Ta struct { A }

type Tb struct { B }

func ConvertSliceToA[From A](vs []From) []A {
var r = make([]A, len(vs))
for i := range vs {
r[i] = vs[i]
}
return r
}

func ConvertSliceToB[From B](vs []From) []B {
var r = make([]B, len(vs))
for i := range vs {
r[i] = vs[i]
}
return r
}

func main() {
var x [100]Ta
var _ = ConvertSliceToA(x[:])

var y [100]Tb
var _ = ConvertSliceToB(y[:])
}

-- 
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/fa05695e-f891-41e3-a647-fff56b6b112cn%40googlegroups.com.