Last active
April 23, 2024 06:00
-
-
Save Micrified/d9ba4574a1d85bd8ec3cf116e197d856 to your computer and use it in GitHub Desktop.
Yet another fail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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