Software /
code /
prosody
Diff
util/iterators.lua @ 4386:ce769240f8ec
util.iterators: Add range(from, to)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 25 Sep 2011 00:20:43 +0100 |
parent | 3540:bc139431830b |
child | 4441:a01b7207cb37 |
line wrap: on
line diff
--- a/util/iterators.lua Thu Sep 22 15:48:56 2011 +0100 +++ b/util/iterators.lua Sun Sep 25 00:20:43 2011 +0100 @@ -120,6 +120,12 @@ --return reverse(head(n, reverse(f, s, var))); end +local function _range_iter(max, curr) if curr < max then return curr + 1; end end +function range(x, y) + if not y then x, y = 1, x; end -- Default to 1..x if y not given + return _range_iter, y, x-1; +end + -- Convert the values returned by an iterator to an array function it2array(f, s, var) local t, var = {}; @@ -142,3 +148,4 @@ end return t; end +