86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
...
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
...
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
local new = fn.copy(r1)
for i=1,#r2 do
new[#new + 1] = r2[i]
end
return new
end
fn.capitalize = function(str)
return string.upper(string.sub(str, 1,1)) .. string.sub(str, 2)
end
fn.has = function(tbl,value,eqfn)
for k,v in pairs(tbl) do
if eqfn then
if eqfn(v,value,tbl) then return true, k end
else
if value == v then return true, k end
end
................................................................................
table.sort(keys)
return fn.each(keys, function(k,i)
return f(tbl[k],k,i)
end)
end
fn.iter = function(tbl,fn)
for i=1,#tbl do
fn(tbl[i], i)
end
end
fn.map = function(tbl,fn)
local new = {}
for k,v in pairs(tbl) do
local nv, nk = fn(v, k)
new[nk or k] = nv
................................................................................
fn.fold = function(tbl,fn,acc)
if #tbl == 0 then
fn.each_o(tbl, function(v)
acc = fn(acc, v, k)
end)
else
for i=0,#tbl do
acc = fn(acc,tbl[i],i)
end
end
return acc
end
fn.walk = function(tbl,path)
if type(path) == 'table' then
|
|
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
...
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
local new = fn.copy(r1)
for i=1,#r2 do
new[#new + 1] = r2[i]
end
return new
end
fn.has = function(tbl,value,eqfn)
for k,v in pairs(tbl) do
if eqfn then
if eqfn(v,value,tbl) then return true, k end
else
if value == v then return true, k end
end
................................................................................
table.sort(keys)
return fn.each(keys, function(k,i)
return f(tbl[k],k,i)
end)
end
fn.iter = function(tbl,fn)
for i,v in ipairs(tbl) do fn(v, i) end
end
fn.map = function(tbl,fn)
local new = {}
for k,v in pairs(tbl) do
local nv, nk = fn(v, k)
new[nk or k] = nv
................................................................................
fn.fold = function(tbl,fn,acc)
if #tbl == 0 then
fn.each_o(tbl, function(v)
acc = fn(acc, v, k)
end)
else
for i,v in ipairs(tbl) do
acc = fn(acc,v,i)
end
end
return acc
end
fn.walk = function(tbl,path)
if type(path) == 'table' then
|