[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Conventional name proposal: merge
- From: Rapin Patrick <rapin.patrick@...>
- Date: Fri, 14 Dec 2012 21:09:07 +0100
In LuaDura, I wrote a function named `array_concat`.
An important difference compared to other implementations so far is that it operates _recursively_.
Its goal is to "flatten" a hierarchy of arrays into a single array (or sequence).
function dura.array_concat(...)
local res, arg = {}, {...}
local function insert(val)
if type(val) == 'table' and (#val > 0 or next(val) == nil) then
for _,j in ipairs(val) do
insert(j)
end
else
table.insert(res, val)
end
end
insert(arg)
return res
end
--
-- Patrick Rapin
-- coauthor of "Le guide de Lua et ses applications", D-BookeR