projects
/
prosody.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
6865145
)
util.iterators: Add iterator wrapper that works like select(n, ...) applied to origin...
author
Kim Alvefur
<zash@zash.se>
Fri, 15 Apr 2016 11:20:31 +0000
(13:20 +0200)
committer
Kim Alvefur
<zash@zash.se>
Fri, 15 Apr 2016 11:20:31 +0000
(13:20 +0200)
util/iterators.lua
patch
|
blob
|
history
diff --git
a/util/iterators.lua
b/util/iterators.lua
index 5f03bd10c684bbb07c7a61781a99a9b27855f8ab..bd150ff28cd3572ca407274a9bf4df2276e827df 100644
(file)
--- 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 = {};