[Golang] Returning a func

golang returning a func

  • return func from func
    • ex.
      package main
      
      import "fmt"
      
      func main() {
      	x := bar()
      
      	fmt.Printf("%T\n", x) // func() int
      
      	fmt.Println(x()) // 451
      
      	fmt.Println(bar()()) // 451
      }
      
      func bar() func() int {
      	return func() int {
      		return 451
      	}
      }
      

       

    • End