lua-users home
lua-l archive

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


On Thu, Dec 20, 2012 at 6:02 PM, Philipp Janda <siffiejoe@gmx.net> wrote:
> Thinking about it: one could merge filter and map into one function. If the
> provided function returns a nil value, skip/remove that whole (i)pair/tuple
> altogether, else the return value is the new value. Let's call this function
> "transmogrify"

Yes, map() has to currently handle nil values in some way (I chose
false) to preserve the array-ness and the size of the output.  So a
combined function is nice, and we are free to define its meaning!

> And collect/icollect ([1], slightly altered) are actually surprisingly
> interesting:
>     icollect( {}, 2, ipairs( t ) )       --> shallow_arraycopy( t )
>     icollect( {}, 1, io.lines( fname ) ) --> my @lines = <FILE>;

That is one clever function - I like it!

steve d.