Go to file
Roland 6fe8d76d50
Merge pull request #71 from jamesachamp/patch-1
Fixed typo in README.
2019-11-10 07:31:21 +00:00
doc Added mapi (Fixes #68) 2019-04-01 23:58:38 +00:00
rockspec Added 2.1.0 rockspec 2018-09-12 12:00:23 +00:00
spec Added mapi (Fixes #68) 2019-04-01 23:58:38 +00:00
.gitignore Removed Telescope, added Busted, cleanup 2018-08-23 00:02:09 +00:00
.luacov Updates and fixes 2018-08-23 10:16:57 +00:00
.travis.yml Changed Telescope to busted 2018-08-22 23:46:50 +00:00
CHANGELOG.md Added mapi (Fixes #68) 2019-04-01 23:58:38 +00:00
LICENSE Updated LICENSE 2018-08-22 19:23:41 +00:00
README.md Fixed typo 2019-11-09 21:48:49 -05:00
moses.lua Added mapi (Fixes #68) 2019-04-01 23:58:38 +00:00
moses_min.lua Added mapi (Fixes #68) 2019-04-01 23:58:38 +00:00

README.md

Build Status Latest Stable License Lua

A Lua utility-belt library for functional programming.

Examples

How can I get the sum of all integers between 1 and 100 ?

local sum = M.sum(M.range(100))
print(sum) -- 5050

Say I am looking for the length of the longest word in some array ?

local words = {'some','words','of','different','lengths'}
print(M.max(words, M.op.length)) -- 9 letters

What is the sum of all fibonacci numbers for n below or equal 25 ?

local function fib(n) return n < 2 and n or fib(n - 1) + fib(n - 2) end
local fibsum = M.sum(M.map(M.range(25), fib))
print(fibsum) -- 196417

Or let us do the same, object-oriented style with chaining :

local function fib(n) return n < 2 and n or fib(n - 1) + fib(n - 2) end
local fibsum = M.chain(M.range(25)):map(fib):sum():value()
print(fibsum) -- 196417

Or even shorter :

local fibsum = M(M.range(25)):map(fib):sum():value()
print(fibsum) -- 196417

Feel free to download and try it on your own!

Download

Archive

Bash

git clone git://github.com/Yonaba/Moses.git

LuaRocks

luarocks install moses

MoonRocks

moonrocks install moses

Usage

local M = require "moses"

Note: the full source moses.lua is quite heavy (~92 kiB, 3115 LOC). You can alternatively use the minified version (~35 kiB, 561 LOC).

Tutorial

Find a complete set of code examples in tutorial.md.

Documentation

Credits and Acknowledgement

Specification

Run spec tests from Lua using busted with the following command from the root folder:

busted

License

This work is under MIT-LICENSE
Copyright (c) 2012-2018 Roland Yonaba.
See LICENSE.