mercredi 22 juillet 2020

Go: Get return type of a function

I'm writing higher order functions in Go, and am trying to figure out the return type of the inner function f.

As a simple example, let's say I want to return the default value of the return type of the inner function:

  • if f returns string, GetDefault(f) returns ""
  • if f returns []byte, GetDefault(f) return []byte{}
func GetDefault(func(interface{})) {
  // How would I write this function?
}

Is it possible to write such a function in Go, without running f?





Aucun commentaire:

Enregistrer un commentaire