# HG changeset patch
# User Matthew Wild <mwild1@gmail.com>
# Date 1316906443 -3600
# Node ID ce769240f8ec464092e9f0640e4a440aa3f1ec83
# Parent  c94167139f271048c69a0f55dc40b1182bb5e63f
util.iterators: Add range(from, to)

diff -r c94167139f27 -r ce769240f8ec util/iterators.lua
--- 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
+