Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
11
Task/Function-composition/Go/function-composition-1.go
Normal file
11
Task/Function-composition/Go/function-composition-1.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
// Go doesn't have generics, but sometimes a type definition helps
|
||||
// readability and maintainability. This example is written to
|
||||
// the following function type, which uses float64.
|
||||
type ffType func(float64) float64
|
||||
|
||||
// compose function requested by task
|
||||
func compose(f, g ffType) ffType {
|
||||
return func(x float64) float64 {
|
||||
return f(g(x))
|
||||
}
|
||||
}
|
||||
17
Task/Function-composition/Go/function-composition-2.go
Normal file
17
Task/Function-composition/Go/function-composition-2.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package main
|
||||
|
||||
import "math"
|
||||
import "fmt"
|
||||
|
||||
type ffType func(float64) float64
|
||||
|
||||
func compose(f, g ffType) ffType {
|
||||
return func(x float64) float64 {
|
||||
return f(g(x))
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
sin_asin := compose(math.Sin, math.Asin)
|
||||
fmt.Println(sin_asin(.5))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue