Apply a callback to an array: Difference between revisions

F#
(map array in autohotkey)
(F#)
Line 503:
{square * . [id, id]}
& square: <1,2,3,4,5>
 
=={{header|F_Sharp|F#}}==
Apply a named function to each member of the array. The result is a new array of the same size as the input.
let evenp x = x % 2 = 0
let result = Array.map evenp [| 1; 2; 3; 4; 5; 6 |]
The same can be done using anonymous functions, this time squaring the members of the input array.
let result = Array.map (fun x -> x * x) [|1; 2; 3; 4; 5|]
 
=={{header|Groovy}}==
Anonymous user