Page 1 of 1

[Lib/Lua] Moses 2.1.0

Posted: Mon Jul 14, 2014 5:51 pm
by Roland_Yonaba
Hi all,

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)
The code below does the exact same thing, but uses chaining:

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()
Or let us consider a dataset of records:

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},
}
We want to find out how many times Allan got connected:

Code: Select all

print(_.count(_.pluck(logs, 'name'), 'Allan')) --> 4
Or find out the max timestamp:

Code: Select all

print(_.max(_.pluck(logs, 'timestamp'))) --> 578
Or get the list of the unique visitors to the database:

Code: Select all

_.each(_.unique(_.pluck(logs, 'name')),print) --> 'Allan', 'John', 'Ronald', 'Peter', 'Steve'
or the same list, chaining style:

Code: Select all

_(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

Re: [Lib/Lua] Moses 1.4.0

Posted: Tue Jul 22, 2014 10:03 am
by SiENcE
Nice!

Now I need a löve database :).

Re: [Lib/Lua] Moses 2.1.0

Posted: Sun Sep 23, 2018 7:09 am
by Roland_Yonaba
Hi all,

Sorry to bring up that old thread, I just did not want to create a new one.
This library have been updated to version 2.1.0, which adds a lots of new features, changes and fixes.
Feel free to peek at the tutorial, or the documentation. Project page can be found here.

Hope you like it.