Apply a callback to an array: Difference between revisions

Content added Content deleted
(adding gap)
Line 590: Line 590:
Use ''iter'' if the applied function does not return a value.
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>
<lang fsharp>Array.iter (fun x -> printfn "%d" x) [|1; 2; 3; 4; 5|]</lang>
=={{header|GAP}}==
<lang gap>
a := [1 .. 4];
b := ShallowCopy(a);

# Apply and replace values
Apply(a, n -> n*n);
a;
# [ 1, 4, 9, 16 ]

# Apply and don't change values
Perform(b, Display);
1
2
3
4

b;
# [ 1 .. 4 ]</lang>

=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<lang go>package main