You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
573 B
Lua
20 lines
573 B
Lua
--- Helper moduile for performing a function on each element in an array.
|
|
-- @module lqc.helpers.map
|
|
-- @alias map
|
|
--- Maps a function over an array
|
|
-- @param array List of elements on which a function will be applied
|
|
-- @param func Function to be applied over the array. Takes 1 argument (element of the array); returns a result
|
|
-- @return A new array with func applied to each element in the array
|
|
local function map(array, func)
|
|
local result = {}
|
|
|
|
for idx = 1, #array do
|
|
result[#result + 1] = func(array[idx])
|
|
end
|
|
|
|
return result
|
|
end
|
|
|
|
return map
|
|
|