Move func.iterate to iterator.foreach

This commit is contained in:
Lars Mueller 2022-09-07 11:48:24 +02:00
parent 2a133df40d
commit 6d527b0471
2 changed files with 10 additions and 9 deletions

@ -49,15 +49,6 @@ function memoize(func)
})
end
-- Equivalent to `for x, y, z in iterator, state, ... do callback(x, y, z) end`
function iterate(callback, iterator, state, ...)
local function loop(...)
if ... == nil then return end
callback(...)
return loop(iterator(state, ...))
end
return loop(iterator(state, ...))
end
function for_generator(caller, ...)
local co = coroutine.create(function(...)

@ -4,6 +4,16 @@ local add = modlib.func.add
--+ Otherwise they will be applied to the indices.
local iterator = {}
-- Equivalent to `for x, y, z in iterator, state, ... do callback(x, y, z) end`
function iterator.foreach(callback, iterator, state, ...)
local function loop(...)
if ... == nil then return end
callback(...)
return loop(iterator(state, ...))
end
return loop(iterator(state, ...))
end
function iterator.range(from, to, step)
if not step then
if not to then