mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-29 10:43:43 +01:00
Move func.iterate to iterator.foreach
This commit is contained in:
parent
2a133df40d
commit
6d527b0471
9
func.lua
9
func.lua
@ -49,15 +49,6 @@ function memoize(func)
|
|||||||
})
|
})
|
||||||
end
|
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, ...)
|
function for_generator(caller, ...)
|
||||||
local co = coroutine.create(function(...)
|
local co = coroutine.create(function(...)
|
||||||
|
10
iterator.lua
10
iterator.lua
@ -4,6 +4,16 @@ local add = modlib.func.add
|
|||||||
--+ Otherwise they will be applied to the indices.
|
--+ Otherwise they will be applied to the indices.
|
||||||
local iterator = {}
|
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)
|
function iterator.range(from, to, step)
|
||||||
if not step then
|
if not step then
|
||||||
if not to then
|
if not to then
|
||||||
|
Loading…
Reference in New Issue
Block a user