This commit is contained in:
Nikita Kruglickiy
2021-11-12 18:27:28 +03:00
17 changed files with 605 additions and 66 deletions

View File

@@ -93,3 +93,15 @@ function table.find(tbl, predicate)
end
end
end
function table.reduce(tbl, func, init)
init = init or 0
local accum = init
for _, field in ipairs(tbl) do
accum = accum + func(field)
end
return accum
end

View File

@@ -0,0 +1,14 @@
function watcher(expr, cbk)
local lastVal = expr()
return function()
local newVal = expr()
if newVal == lastVal then
return
end
cbk(newVal, lastVal)
lastVal = newVal
end
end