Hi all,
Moses bumped to version
1.4.0.
Moses is mostly meant for functional programming, with Lua. It provides functions to operates on tables array-style, list-style, collection-style or object-style.
Here are some example:
local _ = require 'moses'
-- Creates an array of values from 1 to 20
local t = _.range(1,20)
-- Filter even values
t = _.select(t, function(i,v) return v%2~=0 end)
-- Double all values
t = _.map(t, function(i,v) return v*2 end) |
The code below does the exact same thing, but uses chaining:
local _ = require 'moses'
local t = _:chain(_.range(1,20))
:select(function(i,v) return v%2~=0 end)
:map(function(i,v) return v*2 end)
:value() |
Or let us consider a dataset of records:
local logs = {
{name = 'Allan', timestamp = 00578}, {name = 'John', timestamp = 20578},
{name = 'Ronald', timestamp = 00579}, {name = 'Ronald', timestamp = 30578},
{name = 'John', timestamp = 0057}, {name = 'Allan', timestamp = 0678},
{name = 'Allan', timestamp = 00278}, {name = 'Peter', timestamp = 06578},
{name = 'Peter', timestamp = 30578}, {name = 'Allan', timestamp = 0878},
{name = 'Steve', timestamp = 50578}, {name = 'John', timestamp = 078},
} |
We want to find out how many times
Allan got connected:
print(_.count(_.pluck(logs, 'name'), 'Allan')) --> 4 |
Or find out the max timestamp:
print(_.max(_.pluck(logs, 'timestamp'))) --> 578 |
Or get the list of the unique visitors to the database:
_.each(_.unique(_.pluck(logs, 'name')),print) --> 'Allan', 'John', 'Ronald', 'Peter', 'Steve' |
or the same list, chaining style:
_(logs):pluck('name'):unique():each(print) --> 'Allan', 'John', 'Ronald', 'Peter', 'Steve' |
Find a complete tutorial
here on Moses' API. The documentation is also available
online, on in HTML format bundled with the library.
Moses 1.4.0 :
source |
Github |
Url
Comments
thanks for the lib, your lib is really well commented
http://www.nightspade.com
@___ : _.import() is available now.
I also see some new stuff
I've been lately working on nifty updates, bringing Moses to version 1.2
New functions are availables.
See the project page, and feel free to like it, pull requests, fork it on Github.
Link: http://yonaba.github.com/Moses
Github: http://github.com/Yonaba/Moses
I've been working the past days on a full update of Moses, fixing lots of inconsistencies, briging several patches, adding new features and setting a clean specification code. I've released the latest stable.
As a recall, Moses (deeply inspired by Underscore.js) is a utility-belt library providing support for functional programming.
It complements the built-in Lua table library, making easier operations on arrays, lists,
collections, objects, through an easy-to-use API of 98 functions.
Project lives at: Moses (Github)
Latest stable: Moses 1.3.2.1
A fully complete documentation is available in both markdown and Html output (thanks to the awesome LDoc, from S. Donovan).
Thanks reading!
Regards,
Roland.
Likes: OZApps, vitalitymobile
Moses just bumped to version 1.4.0.
I have updated the OP. Find below some useful links.
Moses 1.4.0 : source | Github | Url