မဝ်ဂျူ:table/slice
မံက်ပြာကတ်
Documentation for this module may be created at မဝ်ဂျူ:table/slice/doc
local index_module = "Module:index"
local table_length_module = "Module:table/length"
local require = require
local function index_range(...)
index_range = require(index_module).range
return index_range(...)
end
local function table_len(...)
table_len = require(table_length_module)
return table_len(...)
end
--[==[
Given a list, returns a new list consisting of the items between the start index `i` and end index `j` (inclusive). `i` defaults to `1`, and `j` defaults to the length of the input list.]==]
return function(t, i, j)
local slice, n = {}, 0
i, j = index_range(t, i, j, table_len)
while not (j and i > j) do
local v = t[i]
if v == nil then
return slice
end
n = n + 1
slice[n] = v
i = i + 1
end
return slice
end