Files
the-way-to-go_ZH_CN/eBook/exercises/chapter_6/compose.go
2017-02-11 12:24:19 +08:00

18 lines
283 B
Go
Executable File

// compose.go
package main
import (
"fmt"
"math"
)
func Compose(f, g func(x float64) float64) func(x float64) float64 {
return func(x float64) float64 { // closure
return f(g(x))
}
}
func main() {
fmt.Print(Compose(math.Sin, math.Cos)(0.5)) // output: 0.7691963548410085
}