Moses
Utility library for functional programming in Lua
Install / Use
/learn @Yonaba/MosesREADME
A Lua utility-belt library for functional programming.<br/>
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
- Read it online.
Credits and Acknowledgement
- Jeremy Ashkenas, for the amazing Underscore.js
- Marcus Irven's and JT Archie's 1-to-1 ports that also inspired this
- Matthew Rocklin's Toolz from which I borrowed some ideas
- Steve Donovan's LDoc, used to generate the current HTML documentation.
- Mark Langen's LuaMinify, used to generate a minified version of this library.
Specification
Run spec tests from Lua using busted with the following command from the root folder:
busted
License
This work is under MIT-LICENSE<br/> Copyright (c) 2012-2018 Roland Yonaba. <br/> See LICENSE.
Related Skills
node-connect
341.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
341.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.6kCommit, push, and open a PR

