map
Creates a new array from calling a function on every array element
(map fn arr)
Returns
The function returns a new array that contains the transformed values after applying the specified function to each element of the input array.
Parameters
fn (lambda) - the function to be applied to each element of the array.
arr (array) - the input array containing elements to be transformed.
Examples
(map inc [1, 2, 3, 4, 5]) ;; increment all values
;;=> [2, 3, 4, 5, 6]
(map (fn [x] (* x 2)) [1, 2, 3, 4]) ;; multiply all values with 2
;;=> [2, 4, 6, 8]
(map (fn [symbol] {symbol}) ["AAPL", "MSFT"]) ;; creates an array of assets
;;=> [{symbol: "AAPL", close: ...}, {symbol: "MSFT", close: ...}]
Was this helpful?