lua-users home
lua-l archive

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


Can lua-iterators be used inside posix style event loops like luasys.evq or cqueues?

Sent from my BlackBerry 10 smartphone on the Virgin Mobile network.
  Original Message  
From: Adrián Pérez de Castro
Sent: Tuesday, September 13, 2016 1:09 PM
To: Lua mailing list
Reply To: Lua mailing list
Subject: Re: [ANN] itertools 0.1 - Functional iterators based on coroutines

Quoting Daurnimator (2016-09-13 03:58:25)
> On 12 September 2016 at 21:24, Adrián Pérez de Castro <aperez@igalia.com> wrote:
> > The lua-itertools module provides a collection of functional utilities to use
> > with coroutine-based iterators. One of the main goals is to provide composable
> > functions which work well together. Parts of the API are loosely based on some
> > of the Python builtins (e.g. map, filter), and the itertools [1] module.
> >
> > So far the module includes functionality that I have needed myself. I am open
> > to add additional functions — even if it's just a suggestion, contributions
> > are appreciated :-)
> 
> Do you know of luafun? https://github.com/rtsisyk/luafun
> Although you wouldn't think it from the copy, it doesn't require
> luajit, and works well with lua 5.1 through 5.3.

Oh, the description for luafun was certainly misleading then: I understood
that it requires LuaJIT. I have been playing with it a bit now... and while
it's nice and works well, I get this feeling that the API is forcing me to
write clunky code:

for it_, element in iter( ... ) do
-- "it_" is internal state to be ignored
end

I would rather use a coroutines like in itertools, and keep the iteration
state in variables local to the coroutine, which makes the loops look nicer:

for element in iter( ... ) do
-- no internals are "leaked" outside of the iterator
end

Thanks for letting me know that luafun works in stock Lua, though! :-)

Cheers,

--
☛ Adrián