refactor(parser): Move utility functions to table utils

This commit is contained in:
Simrat Grewal
2022-08-15 14:18:48 -07:00
parent fb2ab3bb1c
commit 0250f77085
2 changed files with 35 additions and 28 deletions

View File

@@ -0,0 +1,31 @@
local M = {}
function M.table_to_str(t)
local ret = ''
for _, value in ipairs(t) do
ret = ret .. tostring(value)
end
return ret
end
function M.str_to_table(str)
local t = {}
for i = 1, #str do
t[i] = str:sub(i, i)
end
return t
end
--- Copies an array and returns it because lua usually does references
---@generic T
---@param t T[]
---@return T[]
function M.array_copy(t)
local ret = {}
for _, value in ipairs(t) do
table.insert(ret, value)
end
return ret
end
return M