Functions
Higher-order functions
package main
import (
"fmt"
)
func power(fn func(int) int) func(int) int { // <--- high-order function
return func(x int) int {
return fn(x)
}
}
func square(x int) int {
return x * x
}
func cube(x int) int {
return x * x * x
}
func main() {
squareFunc := power(square)
cubeFunc := power(cube)
fmt.Println(squareFunc(2)) // Output: 4
fmt.Println(cubeFunc(2)) // Output: 8
}Anonymous functions/Closures/Lambda Functions
Monads
Functors
Monoids
Last updated