lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Sat, Jan 2, 2010 at 10:28 AM, Wim Couwenberg
<> wrote:
> But I agree.  It can turn into a very useful little library!

+1, small, focused and useful.

In fact, I now see the point of passing both the key and the value in
the iterator chain, since then any Lua table can be passed on. Nil
values are also no problem.  One can always define 'vmap' which takes
a function operating only on the values, and of course being able to
operate on the keys as well can be very useful.

Another useful iterator operator is 'take', which returns the first n
values of an iterator; Given 'skip' as well, then you have iterator

Here is a one-line version of the 'head' command:

iseq(io.lines(arg[1])) (take,10) (foreach, print)

steve d.