Moses

Utility library for functional programming in Lua

Github星跟蹤圖

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, opbject-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.

主要指標

概覽
名稱與所有者Yonaba/Moses
主編程語言Lua
編程語言Lua (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2012-07-24 08:42:19
推送於2019-12-18 02:39:18
最后一次提交2019-11-10 07:31:21
發布數7
最新版本名稱Moses-2.1.0-1 (發布於 2018-09-16 09:49:51)
第一版名稱Moses-1.4.0-1 (發布於 2014-07-14 12:19:00)
用户参与
星數636
關注者數28
派生數104
提交數357
已啟用問題?
問題數37
打開的問題數4
拉請求數30
打開的拉請求數1
關閉的拉請求數6
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?