lua-users home
lua-l archive

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


Hi all, this is my first time posting to the mailing list!

I've created and posted a functional programming library, which you can download here:
https://bitbucket.org/luafunctional/lua-functional

This was mainly just something I did for fun and because I really enjoy both FP and Lua, and I hope it might be useful! I know there are some other similar resources, so here's some of the attributes of this one:
Pros:
-pretty big set of functions: map, zips, folds, filters, list comprehension, ranges, currying, scans, and mini helper functions.
-documentation
-somewhat well tested (has a test suite)
-"plug and play" (see example below) -- not a module (or maybe this is a con?)

Cons:
-performance not benchmarked/known

I would love any feedback! The source is completely free, so it would be great if anyone wants to incorporate these functions or the library into a different project or library as well.

Here's an example (sum the squares of the odd fibonnacci numbers under 100):
lfunc = dofile('lua-functional.lua')  -- load all functions into the table lfunc
lfunc.loadglobally(lfunc)  -- now all functions are in the global namespace

-- first line generates a list of fibonnacci numbers below 100
fibs = gent({1,2}, function(t,ind) return t[ind-1]+t[ind-2] end, function(t,ind) return geq(ind,100) end)
odd = compose(apply(eq,1),applyn(mod,2,2))
list = listcomp(function(x) return x*x end, fibs, odd)
sum = apply(foldl1,add)
print(sum(list))


Thanks everyone! Again, feedback would be awesome!

Bo