Files
the-way-to-go_ZH_CN/eBook/exercises/chapter_6/compose.go
2015-03-03 12:25:25 -05:00

18 lines
300 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
}