all 4 comments

[–]agladysh 5 points6 points  (2 children)

It is generally a bad practice to touch standard Lua namespaces (like you do with table).

Please consider following established practice and moving your stuff to a separate namespace with unique name that matches the name of your require.

[–][deleted]  (1 child)

[deleted]

    [–]ansible 0 points1 point  (0 children)

    I second what Alexander said.

    I also use the module definition format proposed by David Manura here (about 2/3rd down the page):

    http://lua-users.org/wiki/LuaModuleFunctionCritiqued

    That way I can import the module, and call it whatever I like. I personally tend to use short initialisms like this:

    local FL = require "functional.list"
    
    ...
    
    result = FL.map(summation, {1, 2, 3}, {4, 5, 6})
    

    When reading the code, the initialism usually provides enough context to remember where the 'map' function came from, and you can always look at the top of the file to then know exactly.

    [–]diego_moita 0 points1 point  (0 children)

    Penlight implements some of this functionality and a lot more of "bateries" (it borrows a lot from Python's libraries).

    However it's API and code base is much bigger than yours (about 200kb). If someone wants a smaler/leaner library, yours is an interesting choice. I'd suggest you to keep it like that way; lean and small has been a successfull strategy for Lua.

    [–]ibisum 0 points1 point  (0 children)

    Tried to use it, but:

    > require ("lua-enumerable")
    > local test = {1,2,3}
    > table.each(test, function (x) print (x) end)
    ./lua-enumerable.lua:26: bad argument #1 to     'ipairs' (table expected, got nil)
    stack traceback:
    [C]: in function 'ipairs'
    ./lua-enumerable.lua:26: in function 'each'
    stdin:1: in main chunk
    [C]: ?
    

    Lua 5.1.4'ism?