Skip to content

Instantly share code, notes, and snippets.

@Micrified
Last active April 23, 2024 06:00
Show Gist options
  • Save Micrified/d9ba4574a1d85bd8ec3cf116e197d856 to your computer and use it in GitHub Desktop.
Save Micrified/d9ba4574a1d85bd8ec3cf116e197d856 to your computer and use it in GitHub Desktop.
Yet another fail
package main
import "fmt"
type R interface {
A() string
B() string
}
type C interface {
R
Method(string) func(C)string
}
// ---
type B struct {
m map[string]func(R)string
}
func(b B) A() string {
return "A"
}
func(b B) B() string {
return "B"
}
func(b B) Method(n string) func(C)string {
return map[string]func(C)string {
"A" : C.A,
"B" : C.B,
}[n]
}
func lookup(c C, n string){
fmt.Println(c.Method(n)(c))
}
func main() {
var b B
lookup(b, "A")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment