X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=util%2Fiterators.lua;h=cc50482721b485b5ecce731c820813b0ad203284;hb=edd92fbc05125aab0b1fa14599f74bb5419f96a2;hp=ba33bc80b1e5ebb417dc6513ff5eaa9317a46390;hpb=95c64b70f7cb28745222146784181e866b515069;p=prosody.git diff --git a/util/iterators.lua b/util/iterators.lua index ba33bc80..cc504827 100644 --- a/util/iterators.lua +++ b/util/iterators.lua @@ -1,6 +1,6 @@ -- Prosody IM --- Copyright (C) 2008-2009 Matthew Wild --- Copyright (C) 2008-2009 Waqas Hussain +-- Copyright (C) 2008-2010 Matthew Wild +-- Copyright (C) 2008-2010 Waqas Hussain -- -- This project is MIT/X11 licensed. Please see the -- COPYING file in the source package for more information. @@ -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