aboutsummaryrefslogtreecommitdiffstats
path: root/util/iterators.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2010-07-20 12:37:28 +0100
committerMatthew Wild <mwild1@gmail.com>2010-07-20 12:37:28 +0100
commit9a9e9b1c1ab8bf74b50686ee5ecb750aec275cbf (patch)
treea1419d76220350b97ae1362c86cb785e6837d974 /util/iterators.lua
parent143af24d62d9f349039cb1dc37b3ec6812325a50 (diff)
downloadprosody-9a9e9b1c1ab8bf74b50686ee5ecb750aec275cbf.tar.gz
prosody-9a9e9b1c1ab8bf74b50686ee5ecb750aec275cbf.zip
util.iterators: Add skip() to skip the first n items of an iterator
Diffstat (limited to 'util/iterators.lua')
-rw-r--r--util/iterators.lua9
1 files changed, 9 insertions, 0 deletions
diff --git a/util/iterators.lua b/util/iterators.lua
index 318c1a96..cc504827 100644
--- a/util/iterators.lua
+++ b/util/iterators.lua
@@ -90,6 +90,15 @@ function head(n, f, s, var)
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