aboutsummaryrefslogtreecommitdiffstats
path: root/util/iterators.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2011-09-25 00:20:43 +0100
committerMatthew Wild <mwild1@gmail.com>2011-09-25 00:20:43 +0100
commit40a31d93d60d780d782f57ac73247533495b32a2 (patch)
treedc944310c6ec4b2f741a01c4d2757bc4df83ae64 /util/iterators.lua
parent3f7fda7079b5655fccfd392399d1ff9aebd1a943 (diff)
downloadprosody-40a31d93d60d780d782f57ac73247533495b32a2.tar.gz
prosody-40a31d93d60d780d782f57ac73247533495b32a2.zip
util.iterators: Add range(from, to)
Diffstat (limited to 'util/iterators.lua')
-rw-r--r--util/iterators.lua7
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
+