This is a creation in Article, where the information may have evolved or changed.
Golang function as type package Mainimport"FMT"type A func (int,int) func (f A) Serve () {fmt. Println ("Serve2")}func serve (int,int) {fmt. Println ("serve1")}func Main () {a:=A (serve) a (1,2) A.serve ()}
Type Functintyoe func (int)BOOL //declares a function typefunc isodd (integerint)BOOL { ifinteger%2==0 { return false } return true} func isEven (integerint)BOOL { ifinteger%2==0 { return true } return false} //declared function type in this place as a parameterfunc filter (slice []int, f Functintyoe) []int { varresult []int for_, Value: =Range Slice {iff (value) {result=Append (result, value)}} returnresult} func Test () {slice:= []int{1,2,3,4,5,7} fmt. Println ("slice =", slice) odd:= Filter (slice, isodd)//function as a value to pass theFmt. Println ("Odd elements of slice are:", Odd) even:= Filter (slice, IsEven)//function as a value to pass theFmt. Println ("even elements of slice are:", even)}