lua-users home
lua-l archive

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


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