generics constraint any vs comparable, type set question
Go 1.22 generics question. I want a function that accepts any map type and returns its keys as a slice. I wrote func keys[K comparable, V any](m map[K]V) []K. Why does K need comparable and not any? And could I write this with a type-set constraint instead? I feel like I'm missing a simpler approach, since every example I find seems to use a type set for something like this.
4 replies