On Thu, Jun 18, 2020, 11:28 T L <tapir....@gmail.com> wrote: > How to declare a generic functions which converting a slice with type Ta > to a slice with type Tb. Like > func ConvertSlice(type Ta, Tb constraint)(ins []Ta) []Tb {...} > > How to constraint a type parameter must be of an interface type? >
I don't think you can. Why would you need to? Note that there will always be constraints that you can't express. > Is it possible to define generic unnamed types? > No. It also would be useless. You can't refer to a generic, uninstantiated type. So a generic type either needs a name to be referred by to instantiate it, or be instantiated right immediately in its declaration (and thus wouldn't need to be generic). If it is impossible, then how to define a generic map type which elements > must be an unnamed integer slice? > type numeric interface { type int, int8, int16, int32, ... } type MyMap(type K comparable, T numeric) map[K][]T -- > 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/f02971c4-7e16-4f33-b919-93e7569d6571o%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/f02971c4-7e16-4f33-b919-93e7569d6571o%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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/CAEkBMfFHFe_RogeoG8Qq_RF4zA-2f%2Bt-W60ZdLQXX01Sh1rW6g%40mail.gmail.com.