mirror of
https://github.com/kepler155c/opus
synced 2025-01-01 03:10:28 +00:00
util refactor
This commit is contained in:
parent
8f4324f1d8
commit
ad60fce9b0
@ -3,6 +3,10 @@ local Util = require('util')
|
||||
|
||||
local Map = { }
|
||||
|
||||
-- TODO: refactor
|
||||
Map.merge = Util.merge
|
||||
Map.shallowCopy = Util.shallowCopy
|
||||
|
||||
function Map.removeMatches(t, values)
|
||||
local function matchAll(entry)
|
||||
for k, v in pairs(values) do
|
||||
@ -25,7 +29,7 @@ function Map.prune(t, fn)
|
||||
for _,k in pairs(Util.keys(t)) do
|
||||
local v = t[k]
|
||||
if type(v) == 'table' then
|
||||
t[k] = Util.prune(v, fn)
|
||||
t[k] = Map.prune(v, fn)
|
||||
end
|
||||
if not fn(t[k]) then
|
||||
t[k] = nil
|
||||
@ -34,4 +38,12 @@ function Map.prune(t, fn)
|
||||
return t
|
||||
end
|
||||
|
||||
function Map.size(list)
|
||||
local length = 0
|
||||
for _ in pairs(list) do
|
||||
length = length + 1
|
||||
end
|
||||
return length
|
||||
end
|
||||
|
||||
return Map
|
||||
|
@ -277,8 +277,9 @@ function Util.filter(it, f)
|
||||
end
|
||||
|
||||
function Util.reduce(t, fn, acc)
|
||||
acc = acc or 0
|
||||
for _, v in pairs(t) do
|
||||
fn(acc, v)
|
||||
acc = fn(acc, v)
|
||||
end
|
||||
return acc
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user