[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Possible Lua enhancements 2: Piping
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Fri, 19 Dec 2008 11:44:53 +0100
2008/12/18 Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>:
>> > pipe(producer(), filter1, filter2, ..., consumer)
>> >
>> That won't work if the producer can generate multiple values and we
>> need to pass those along.
>
> How about
> pipe(producer, filter1, filter2, ..., consumer) (args-to-producer)
>
Or simply:
pipe(function() return producer(args-to-producer) end, filter1,
filter2, ..., consumer)
And if that syntax is still too heavy, you can use a helper function:
pipe(bind(producer, args-to-producer), filter1, filter2, ..., consumer)
function bind(f, ...)
local args = {n=select('#', ...), ...}
return function()
return f(unpack(args, 1, args.n))
end
end