aboutsummaryrefslogtreecommitdiffstats
path: root/util/iterators.lua
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
commit3f87977ddb135a709b9b86eb491aacfdef2cbdf0 (patch)
tree6169bd4fd03e50421fb752ff65bdd9c24454f071 /util/iterators.lua
parent8fb50705d126977940bb6579147936e57e43cf1e (diff)
downloadprosody-3f87977ddb135a709b9b86eb491aacfdef2cbdf0.tar.gz
prosody-3f87977ddb135a709b9b86eb491aacfdef2cbdf0.zip
util.iterators: Add iterator wrapper that works like select(n, ...) applied to original iterator
Diffstat (limited to 'util/iterators.lua')
-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 = {};