From 022ff52b65f323884932972688ae195e65f1e8eb Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 25 Sep 2011 00:20:43 +0100 Subject: util.iterators: Add range(from, to) --- util/iterators.lua | 7 +++++++ 1 file changed, 7 insertions(+) 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 + -- cgit v1.2.3