How to use function as function argument in Go

1 Answer

0 votes
package main

import (
	"fmt"
	"math"
)

func calc(fn func(float64, float64) float64) float64 {
	return fn(2, 5)
}

func main() {
	fmt.Println(calc(math.Pow))
}



/*
run:

32

*/

 



answered Mar 16, 2020 by avibootz

Related questions

1 answer 218 views
218 views asked Nov 4, 2020 by avibootz
1 answer 195 views
1 answer 150 views
150 views asked Feb 28, 2020 by avibootz
...