As we all know Go doesn't have generic methods. The FAQ <https://go.dev/doc/faq#generic_methods> states: * "We do not anticipate that Go will ever add generic methods".* Also the FAQ lists 4 options out of which the last one seems reasonable: * Define that generic methods cannot be used to satisfy interfaces at all.* But for some unknown reason it is considered a "bad design"*.* And so I was thinkinking that maybe the regular functions can be adapted for the usage as methods? Consider this: type Maybe[A any] { value any } func Just[A any](value A) Maybe[A] { return Maybe[A]{value} } func Map[A, B any](_m Maybe[A], f func(A) B) Maybe[B] { if _m.value == nil { return Maybe[B](_m) } value := f(_m.value.(A)) return Maybe[B]{value} } And then the usage: maybeInt := Just(123) maybeInt.Map(func(i int) { return fmt.Printf("%v", i) }).Map(...).Map(...)
Can this break anything? What are the chances of such a proposal to be approved by the Go Team? Specifically I propose that if a regular function is defined with the first parameter name starting with the underscore we should be able to use method call syntax with this function. And at the same time this function should not take part in interface satisfaction in any way. And if there's a method with the same signature this method should be prioritized. So what do you think? -- 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 visit https://groups.google.com/d/msgid/golang-nuts/8ac5ee09-a68f-40b2-b311-94808304fd6en%40googlegroups.com.