Source file tour/moretypes/function-values.go

     1  // +build OMIT
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"math"
     8  )
     9  
    10  func compute(fn func(float64, float64) float64) float64 {
    11  	return fn(3, 4)
    12  }
    13  
    14  func main() {
    15  	hypot := func(x, y float64) float64 {
    16  		return math.Sqrt(x*x + y*y)
    17  	}
    18  	fmt.Println(hypot(5, 12))
    19  
    20  	fmt.Println(compute(hypot))
    21  	fmt.Println(compute(math.Pow))
    22  }
    23  

View as plain text