util.iterators: Add iterator wrapper that works like select(n, ...) applied to origin...
[prosody.git] / util / iterators.lua
index 5f03bd10c684bbb07c7a61781a99a9b27855f8ab..bd150ff28cd3572ca407274a9bf4df2276e827df 100644 (file)
@@ -54,6 +54,15 @@ function it.values(t)
        end, t;
 end
 
+-- Iterate over the n:th return value
+function it.select(n, f, s, var)
+       return function (_s)
+               local ret = pack(f(_s, var));
+               var = ret[1];
+               return ret[n];
+       end, s, var;
+end
+
 -- Given an iterator, iterate only over unique items
 function it.unique(f, s, var)
        local set = {};