开源软件名称(OpenSource Name):Yonaba/Moses开源软件地址(OpenSource Url):https://github.com/Yonaba/Moses开源编程语言(OpenSource Language):Lua 100.0%开源软件介绍(OpenSource Introduction):A Lua utility-belt library for functional programming. ExamplesHow 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! DownloadArchiveBashgit clone git://github.com/Yonaba/Moses.git LuaRocks
MoonRocks
Usagelocal 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). TutorialFind a complete set of code examples in tutorial.md. Documentation
Credits and Acknowledgement
SpecificationRun spec tests from Lua using busted with the following command from the root folder:
LicenseThis work is under MIT-LICENSE |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论