lua-users home
lua-l archive

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

On Dec 18, 2008, at 3:19 AM, Paul Moore wrote:

2008/12/18 Mark Hamburg <>:
On the other hand, I think there is clarity to be gained from:

      producer() >> filter >> consumer

You can read the code left-to-right instead of inside-out and understand
what it does.

An immediate thought - you can do this with a driver function

   pipe(producer(), filter1, filter2, ..., consumer)

which looks to me sufficiently straightforward that I doubt new syntax
is worth it.

That won't work if the producer can generate multiple values and we need to pass those along. One of the key use cases I had been thinking about was iterators and iterators are represented by three values.

	for k, v in pairs( t ) >> filter_key_type( "string" ) do
		-- operate only on key value pairs with keys of type string

One could do this with pipe( consumer, filter, filter, ... ) ( producer() ) probably with the filters in the reverse order, but the nesting makes the logic harder to follow. Or in the simple case of the loop above:

	for k, v in filter_key_type( "string" )( pairs( t ) ) do
		-- operate only on key value pairs with keys of type string

There's also the potential matter of getting order of evaluation "correct" if the filter construction interacts with shared state.