diff options
author | Yonaba <roland.yonaba@gmail.com> | 2018-08-22 23:50:07 +0300 |
---|---|---|
committer | Yonaba <roland.yonaba@gmail.com> | 2018-08-22 23:50:07 +0300 |
commit | 883948808e120cd58c8c3df9f2761f5115bb8e3e (patch) | |
tree | 03caaa455a984869a5ce71120368d667bad23f22 | |
parent | c744202d94f225356dee2ba4629f8312681f6cb0 (diff) |
Updated README and docs
-rw-r--r-- | README.md | 48 | ||||
-rw-r--r-- | doc/index.html | 2 | ||||
-rw-r--r-- | doc/manual/tutorial.md.html | 4 |
3 files changed, 47 insertions, 7 deletions
@@ -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). diff --git a/doc/index.html b/doc/index.html index 7624b02..7108fb6 100644 --- a/doc/index.html +++ b/doc/index.html @@ -6559,7 +6559,7 @@ </div> <!-- id="main" --> <div id="about"> <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i> -<i style="float:right;">Last updated 2018-08-22 19:22:33 </i> +<i style="float:right;">Last updated 2018-08-22 20:49:28 </i> </div> <!-- id="about" --> </div> <!-- id="container" --> </body> diff --git a/doc/manual/tutorial.md.html b/doc/manual/tutorial.md.html index 6fbb729..6cc4cdd 100644 --- a/doc/manual/tutorial.md.html +++ b/doc/manual/tutorial.md.html @@ -2795,7 +2795,7 @@ Moses offers chaining for your perusal. <br/></p> </pre> -<p>For convenience, you can also use <code>_(value)</code> to start chaining methods, instead of <code>M.chain(value)</code>.</p> +<p>For convenience, you can also use <code>M(value)</code> to start chaining methods, instead of <code>M.chain(value)</code>.</p> <p>Note that one can use <code>:value()</code> to unwrap a chained object.</p> @@ -2862,7 +2862,7 @@ M.import(context, <span class="keyword">true</span>) </div> <!-- id="main" --> <div id="about"> <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i> -<i style="float:right;">Last updated 2018-08-22 19:22:33 </i> +<i style="float:right;">Last updated 2018-08-22 20:49:28 </i> </div> <!-- id="about" --> </div> <!-- id="container" --> </body> |