I have written the following code. But I can't have it compiled. Here is my code:
package main
import "fmt"
func main() {
tmp := make([]int, 10)
for i := 0; i < 10; i++ {
tmp[i] = i
}
res := mapx(foo, tmp)
fmt.Printf("%v
", res)
}
func foo(a int) int {
return a + 10
}
func mapx(functionx func(int) int, list []int) (res []int) {
res = make([]int, 10)
for _, i := range(list) {
append(res, functionx(i))
}
return
}
Meanwhile the error message is also very confusing:
prog.go:21: append(res, functionx(i)) not used
But if I replace append(res, functionx(i))
(line 21) with res = append(res, functionx(i))
, it works quite well. Can anybody help me?
Thank you!