• Welcome to the Kancolle Wiki!
  • If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord

Module:Iterator

From Kancolle Wiki
Revision as of 20:01, 19 July 2017 by がか (talk | contribs) (Created page with "local Iterator = {} function Iterator.array(arr, i, n) i = i or 0 n = n and math.min(#arr, n) or #arr function step(n, i) if i < n then i = i ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Iterator/doc

local Iterator = {}

function Iterator.array(arr, i, n)
    i = i or 0
    n = n and math.min(#arr, n) or #arr
    function step(n, i)
        if i < n then
            i = i + 1
            return i, arr[i]
        end
    end
    return function()
        return step, n, i
    end
end

return Iterator