Apply a callback to an array: Difference between revisions

Go solution
(Go solution)
Line 560:
Use ''iter'' if the applied function does not return a value.
<lang fsharp>Array.iter (fun x -> printfn "%d" x) [|1; 2; 3; 4; 5|]</lang>
=={{header|Go}}==
<lang go>package main
 
import "fmt"
 
func applyCallback(a []int, f func(int) int) {
for i, e := range a {
a[i] = f(e)
}
}
 
func inc(n int) int {
return n+1
}
 
func main() {
a := []int{3, 1, 4}
applyCallback(a, inc)
fmt.Println(a)
}</lang>
 
=={{header|Groovy}}==
1,707

edits