diff options
author | Matthew Wild <mwild1@gmail.com> | 2011-09-25 00:20:43 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2011-09-25 00:20:43 +0100 |
commit | 022ff52b65f323884932972688ae195e65f1e8eb (patch) | |
tree | dc944310c6ec4b2f741a01c4d2757bc4df83ae64 /util/iterators.lua | |
parent | 62e023da82e23f87acfaf6ff704d3763376a0b3b (diff) | |
download | prosody-022ff52b65f323884932972688ae195e65f1e8eb.tar.gz prosody-022ff52b65f323884932972688ae195e65f1e8eb.zip |
util.iterators: Add range(from, to)
Diffstat (limited to 'util/iterators.lua')
-rw-r--r-- | util/iterators.lua | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/util/iterators.lua b/util/iterators.lua index dc692d64..2a87e97a 100644 --- a/util/iterators.lua +++ b/util/iterators.lua @@ -120,6 +120,12 @@ function tail(n, f, s, var) --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 @@ function it2table(f, s, var) end return t; end + |