diff options
author | Matthew Wild <mwild1@gmail.com> | 2010-07-20 12:37:28 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2010-07-20 12:37:28 +0100 |
commit | 9a9e9b1c1ab8bf74b50686ee5ecb750aec275cbf (patch) | |
tree | a1419d76220350b97ae1362c86cb785e6837d974 /util | |
parent | 143af24d62d9f349039cb1dc37b3ec6812325a50 (diff) | |
download | prosody-9a9e9b1c1ab8bf74b50686ee5ecb750aec275cbf.tar.gz prosody-9a9e9b1c1ab8bf74b50686ee5ecb750aec275cbf.zip |
util.iterators: Add skip() to skip the first n items of an iterator
Diffstat (limited to 'util')
-rw-r--r-- | util/iterators.lua | 9 |
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 |