aboutsummaryrefslogtreecommitdiffstats
path: root/util/iterators.lua
diff options
context:
space:
mode:
Diffstat (limited to 'util/iterators.lua')
-rw-r--r--util/iterators.lua12
1 files changed, 12 insertions, 0 deletions
diff --git a/util/iterators.lua b/util/iterators.lua
index 08bb729c..6a437dd7 100644
--- a/util/iterators.lua
+++ b/util/iterators.lua
@@ -78,6 +78,18 @@ function count(f, s, var)
return x;
end
+-- Return the first n items an iterator returns
+function head(n, f, s, var)
+ local c = 0;
+ return function (s, var)
+ if c >= n then
+ return nil;
+ end
+ c = c + 1;
+ return f(s, var);
+ end, s;
+end
+
-- Convert the values returned by an iterator to an array
function it2array(f, s, var)
local t, var = {};