# HG changeset patch # User Kim Alvefur # Date 1460719231 -7200 # Node ID 4b4cf01673918ea3370d5241e8d06e6242a3643f # Parent 8ca7f1c2c660e87937a2ea6c61c5308e165f5f08 util.iterators: Add iterator wrapper that works like select(n, ...) applied to original iterator diff -r 8ca7f1c2c660 -r 4b4cf0167391 util/iterators.lua --- a/util/iterators.lua Fri Apr 15 13:19:20 2016 +0200 +++ b/util/iterators.lua Fri Apr 15 13:20:31 2016 +0200 @@ -54,6 +54,15 @@ 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 = {};