X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=util%2Fiterators.lua;h=dc692d64eac36e93a14b07c38488b56de10c5d44;hb=795439b3b41fd0a42fb883124d26f85d6980e99f;hp=ba33bc80b1e5ebb417dc6513ff5eaa9317a46390;hpb=0941c9bd784387284c165757220342286776d436;p=prosody.git diff --git a/util/iterators.lua b/util/iterators.lua index ba33bc80..dc692d64 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. @@ -73,7 +73,7 @@ function count(f, s, var) var = ret[1]; if var == nil then break; end x = x + 1; - end + end return x; end @@ -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 @@ -122,7 +131,7 @@ function it2array(f, s, var) return t; end --- Treat the return of an iterator as key,value pairs, +-- Treat the return of an iterator as key,value pairs, -- and build a table function it2table(f, s, var) local t, var = {};