lua-users home
lua-l archive

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



On Thu, Dec 17, 2009 at 2:43 PM, Tony Finch <dot@dotat.at> wrote:
Traditional functional libraries don't have a map2() function since
it can be trivially defined as something like:
 
In metalua there's an imap (it recycles the"i" of ipairs/pairs convention, to provide list-oriented and hash-oriented functors); it takes an arbitrary number of tables, and therefore supercedes map, map2, map3 etc.
 
inc  = |t|      table.imap(|x| x+1, t)
zip2 = |t1, t2| table.imap(|x,y| {x, y}, t1, t2)
izip = |...|    table.imap(|...| {...}, ...) -- generalized map => generalized zip!

It saves a tuple creation within a loop, too.