Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Yonaba/Moses.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md48
1 files changed, 44 insertions, 4 deletions
diff --git a/README.md b/README.md
index f17be65..bd01a85 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,46 @@
A Lua utility-belt library for [functional programming](http://en.wikipedia.org/wiki/Functional_programming).<br/>
+## Examples
+
+How can I get the sum of all integers between 1 and 100 ?
+
+```lua
+local sum = M.sum(M.range(100))
+print(sum) -- 5050
+````
+Say I am looking for the length of the longest word in some array ?
+
+```lua
+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 ?
+
+```lua
+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 :
+
+```lua
+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 :
+
+```lua
+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
@@ -33,7 +73,7 @@ moonrocks install moses
local _ = require "moses"
````
-*Note:* the full source [moses.lua](https://github.com/Yonaba/Moses/blob/master/moses.lua) is quite heavy (~80 kiB, 2611 LOC). You can alternatively use the [minified version](https://github.com/Yonaba/Moses/blob/master/moses_min.lua) (~30 kiB, 475 LOC).
+*Note:* the full source [moses.lua](https://github.com/Yonaba/Moses/blob/master/moses.lua) is quite heavy (~83 kiB, 2780 LOC). You can alternatively use the [minified version](https://github.com/Yonaba/Moses/blob/master/moses_min.lua) (~32 kiB, 521 LOC).
## Tutorial
@@ -54,16 +94,16 @@ Find a complete set of code examples in [tutorial.md](https://github.com/Yonaba/
## Specification
-Run [spec tests](https://github.com/Yonaba/Moses/blob/master/spec) using [Telescope](https://github.com/norman/telescope) with the following command from the root folder:
+Run [spec tests](https://github.com/Yonaba/Moses/blob/master/spec) from Lua using [Telescope](https://github.com/norman/telescope) with the following command from the root folder:
````
-tsc -f spec/*
+lua tsc -f spec/*
````
## License
This work is under [MIT-LICENSE](http://www.opensource.org/licenses/mit-license.php)<br/>
-Copyright (c) 2012-2017 Roland Yonaba. <br/>
+Copyright (c) 2012-2018 Roland Yonaba. <br/>
See [LICENSE](LICENSE).