package main // A little example of currying in Go // gtowell // Oct 7, 2023 // // Usage curry 3 2 3 4 5 6 // Output // 2 --> 8 // 3 --> 27 // 4 --> 64 // 5 --> 125 // 6 --> 216 import ( "fmt" "math" "os" "strconv" ) // The function that generates the curried function // in this case, the currying function just reduces the number of params to // the math.Pow function by one // It also makes the func work with int args func curryPowInt(power int) func(int) int { a := float64(power) f := func(p int) int { pf := float64(p) v := math.Pow(pf, a) return int(v) } return f } func main() { // get the power to raise things to -- as an integer v,_ := strconv.Atoi(os.Args[1]) // create the curried function pV := curryPowInt(v) // use the function on the remainder of the command line args for i:=2; i %v\n", v, pV(v)); } }