mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 07:34:06 +08:00
18 lines
300 B
Go
Executable File
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
|
|
}
|