lua-users home
lua-l archive

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


There's always the option of having more namespaces.

	table.map( fn, t )
	iter.map( fn, iterFn, iterState, iterVal )

>From the standpoint of using the colon operator to handle the lookup thereby creating more generic code, one really wants table.map( t, fn ) which is fine but this doesn't generalize well to iterators since they involve up to three values.

The other ugly part, however, is lack of convenient chaining support for these sort of constructs.

For example, what I really want to write in your directory example is something like:

	for f in lfs.dir '.' >> iter.map( string.lower ) >> iter.filter( fs.extension_equals, '.zip' ) do

	end

Getting this really right requires a lot more code experimentation.

Without extending Lua, we could do something like:

	for f in iter( lfs.dir '.' ):map( string.lower ):filter( fs.extension_equals, '.zip' ) ):do() do

	end

The final do() isn't essential. It could be elided to () but I find that a bit too obscure and easy to miss. There's also the option of just having the resulting object be an iterator but that forces each iteration through the metamethod lookup and resolution.

There is also the option of trying to do something with the concat operator though I think its right associativity may be problematic for this use.

Mark