-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.lua
More file actions
37 lines (33 loc) · 897 Bytes
/
Copy pathUtils.lua
File metadata and controls
37 lines (33 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
-- Utils.lua
local _, ns = ...
local Utils = ns.Utils
function Utils:DumpTable(value)
if type(value) == 'table' then
local s = '{ '
for k, v in pairs(value) do
if type(k) ~= 'number' then k = '"' .. k .. '"' end
s = s .. '[' .. k .. '] = ' .. self:DumpTable(v) .. ','
end
return s .. '} '
else
return tostring(value)
end
end
function Utils:SplitWhitespace(str)
local words = {}
for word in str:gmatch("%S+") do
table.insert(words, word)
end
return words
end
function Utils:UnpackFirst(t)
local first = table.remove(t, 1) -- Get the first element
return first, t
end
function Utils:Map(func, list)
local new_list = {} -- Create a new table for results
for i, v in ipairs(list) do
new_list[i] = func(v) -- Apply function to each element
end
return new_list
end