aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2016-04-15 13:20:31 +0200
committerKim Alvefur <zash@zash.se>2016-04-15 13:20:31 +0200
commit8c8867a14eed3e8136fa2dfe9567e92ec3c47e3b (patch)
tree6169bd4fd03e50421fb752ff65bdd9c24454f071 /util
parent8a13261fc299ed0b3900761915c6e9d102f72118 (diff)
downloadprosody-8c8867a14eed3e8136fa2dfe9567e92ec3c47e3b.tar.gz
prosody-8c8867a14eed3e8136fa2dfe9567e92ec3c47e3b.zip
util.iterators: Add iterator wrapper that works like select(n, ...) applied to original iterator
Diffstat (limited to 'util')
-rw-r--r--util/iterators.lua9
1 files changed, 9 insertions, 0 deletions
diff --git a/util/iterators.lua b/util/iterators.lua
index 5f03bd10..bd150ff2 100644
--- a/util/iterators.lua
+++ b/util/iterators.lua
@@ -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 = {};