Why we can't have nice things: Generic methods — GopherCon Singapore 2025
Speaker: Axel Wagner Generic methods would allow us to write chaining APIs. This is particularly important for functional iterator patterns, which currently have to stretch over multiple lines, or be awkwardly nested. It would also allow us to properly attach generic code to the type it belongs to. An example is func N[T constraints.Integer](n N) N in package rand: It makes it easier to choose a random time.Duration, for example. But it should really be a method on *rand.Rand. So no one really contests that it would be useful to have this feature. Even the Go team largely agrees. But the omission was intentional. The reasons for it stretch all the way back, to even before Go’s first open source release. In fact, it might be the reason we even got generics at all. I walk through the uses of this feature, the reasons adding generics took so long and how they lead to this omission.