Changeset

7355:4b4cf0167391

util.iterators: Add iterator wrapper that works like select(n, ...) applied to original iterator
author Kim Alvefur <zash@zash.se>
date Fri, 15 Apr 2016 13:20:31 +0200
parents 7354:8ca7f1c2c660
children 7356:f4d51870d212 7374:3e8851b7c6e8
files util/iterators.lua
diffstat 1 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 = {};