diff options
author | Kim Alvefur <zash@zash.se> | 2016-04-15 13:20:31 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2016-04-15 13:20:31 +0200 |
commit | 3f87977ddb135a709b9b86eb491aacfdef2cbdf0 (patch) | |
tree | 6169bd4fd03e50421fb752ff65bdd9c24454f071 | |
parent | 8fb50705d126977940bb6579147936e57e43cf1e (diff) | |
download | prosody-3f87977ddb135a709b9b86eb491aacfdef2cbdf0.tar.gz prosody-3f87977ddb135a709b9b86eb491aacfdef2cbdf0.zip |
util.iterators: Add iterator wrapper that works like select(n, ...) applied to original iterator
-rw-r--r-- | util/iterators.lua | 9 |
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 = {}; |