util.iterators: Add skip() to skip the first n items of an iterator
authorMatthew Wild <mwild1@gmail.com>
Tue, 20 Jul 2010 12:37:28 +0100
changeset 3392 6e31b49c4ab8
parent 3391 8ac3f60af3c4
child 3393 5b8de0731c4d
util.iterators: Add skip() to skip the first n items of an iterator
util/iterators.lua
--- a/util/iterators.lua	Sun Jul 18 17:50:38 2010 +0500
+++ b/util/iterators.lua	Tue Jul 20 12:37:28 2010 +0100
@@ -90,6 +90,15 @@
 	end, s;
 end
 
+-- Skip the first n items an iterator returns
+function skip(n, f, s, var)
+	for i=1,n do
+		var = f(s, var);
+	end
+	return f, s, var;
+end
+
+-- Return the last n items an iterator returns
 function tail(n, f, s, var)
 	local results, count = {}, 0;
 	while true do