mirror of
https://github.com/bjc/prosody.git
synced 2025-04-04 13:47:41 +03:00
util.iterators: Add iterator wrapper that works like select(n, ...) applied to original iterator
This commit is contained in:
parent
8fb50705d1
commit
3f87977ddb
1 changed files with 9 additions and 0 deletions
|
@ -54,6 +54,15 @@ function it.values(t)
|
||||||
end, t;
|
end, t;
|
||||||
end
|
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
|
-- Given an iterator, iterate only over unique items
|
||||||
function it.unique(f, s, var)
|
function it.unique(f, s, var)
|
||||||
local set = {};
|
local set = {};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue