Module:table/extend
Jump to navigation
Jump to search
Documentation for this module may be created at Module:table/extend/doc
local insert = table.insert
local select = select
--[==[
Extend an existing list by a new list, modifying the existing list in-place. Compare the Python expression {list.extend(new_items)}.]==]
return function(t, ...)
local i = 0
if select("#", ...) < 2 then
local list = ...
while true do
i = i + 1
local v = list[i]
if v == nil then
return t
end
insert(t, v)
end
else
local pos, list = ...
while true do
i = i + 1
local v = list[i]
if v == nil then
return t
end
insert(t, pos, v)
pos = pos + 1
end
end
end