Function semantics

Higher-order functions

A higher-order function accepts or returns a function. A typed callback expresses the required input and result without coupling the caller to a concrete implementation. Example output: '25'.

Formal Syntax & Structure

go syntaxgo
func apply(f func(int) int, x int) int

Working Example

Example Snippetgo
package main
import "fmt"
func apply(f func(int) int, x int) int { return f(x) }func main() {  fmt.Println(apply(func(n int) int { return n * n }, 5))}
Go Reference