Can I set function pointer to function with receiver simpler than creating function around it?
package main
import "fmt"
type hello struct {
name string
}
func (obj *hello) hello() {
fmt.Printf("Hello %s\n", obj.name)
}
func ntimes(action func (), n int) {
for i := 0; i < n; i++ {
action()
}
}
func main() {
obj := hello{"world"}
// Can I do following simpler?
ntimes(func() {obj.hello();}, 3)
}
Not right now. But with Go 1.1 this will be possible. Go 1.1 Function Calls
Go 1.1 will be ready when the blue line touches zero.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With