On Sat, Sep 10, 2022 at 8:16 PM Alexander Chernoskutov wrote:
I would like to propose a third argument to `table.remove (list [, pos
[, count]])`
`count` - number of elements to remove starting from position `pos`
(defaults to 1). All the removed values are returned.
Right know there's no good way to remove `count` elements from a table.
By using table.move(), it is possible to create implementation with O(#t) time complexity:
function table.remove_count (list, pos, count)
pos = pos or #list
count = count or 1
return
(
function (...)
table.move(list, pos + count, #list + count, pos)
return ...
end
)
(
table.unpack(list, pos, pos + count - 1)
)
end