Software /
code /
prosody
Diff
util/iterators.lua @ 3392:6e31b49c4ab8
util.iterators: Add skip() to skip the first n items of an iterator
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 20 Jul 2010 12:37:28 +0100 |
parent | 2923:b7049746bd29 |
child | 3540:bc139431830b |
line wrap: on
line diff
--- 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