Software /
code /
prosody
Changeset
4386:ce769240f8ec
util.iterators: Add range(from, to)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 25 Sep 2011 00:20:43 +0100 |
parents | 4385:c94167139f27 |
children | 4387:06161b0b83f2 |
files | util/iterators.lua |
diffstat | 1 files changed, 7 insertions(+), 0 deletions(-) [+] |
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 +