How to use function as map's key
dictionary, function, go, key
Solution
You can use `reflect`.
import (
"reflect"
"math"
)
func foo () {
table := make(map[uintptr] string)
table[reflect.ValueOf(math.Sin)] = "Sin"
table[reflect.ValueOf(math.Cos)] = "Cos"
println(table[reflect.ValueOf(math.Cos)])
}
Problem
How to use function as map's key? for example: ``` type Action func(int) func test(a int) { } func test2(a int) { } func main() { x := map[Action]bool{} x[test] = true x[test2] = false } ``` those code would show an error: `invalid map key type Action`