[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Iterator question
- From: Dirk Laurie <dirk.laurie@...>
- Date: Wed, 12 Jun 2013 06:31:34 +0200
2013/6/12 <meino.cramer@gmx.de>:
> is it possible (and how) to create an iterator with lua, which returns
> the [n]th _and_ the [n+1]th value of in array/table with each call?
It is trivial if you are willing to create a new closure each time.
function brix(a)
local i,n=0,#a
return function()
i=i+1
if i<n then return a[i],a[i+1] end
end
end