I have been working the past days on updating this mammoth (yeah, it is quite huge, as of now).
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:
Code: Select all
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)
Code: Select all
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()
Code: Select all
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},
}
Code: Select all
print(_.count(_.pluck(logs, 'name'), 'Allan')) --> 4
Code: Select all
print(_.max(_.pluck(logs, 'timestamp'))) --> 578
Code: Select all
_.each(_.unique(_.pluck(logs, 'name')),print) --> 'Allan', 'John', 'Ronald', 'Peter', 'Steve'
Code: Select all
_(logs):pluck('name'):unique():each(print) --> 'Allan', 'John', 'Ronald', 'Peter', 'Steve'
Moses 1.4.0 : source | Github | Url