Is it possible to write a generic function which converts a slice of a 
concrete type to a slice of an interface that type implements? Something 
like this...

// generic version of []*x -> []X (does not compile)
func gslice[From interface{ ~To }, To any](from []From) []To {
    var to []To
    for _, v := range from {
        to = append(to, v)
    }
    return to
}

https://go.dev/play/p/0GseKk3qOCT

--
Frank

-- 
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/e4543d89-63b9-4608-b1f3-e596f39795can%40googlegroups.com.

Reply via email to