[Lib/Lua] Moses 2.1.0

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

[Lib/Lua] Moses 2.1.0

Post 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
Last edited by Roland_Yonaba on Sun Sep 23, 2018 7:04 am, edited 1 time in total.
User avatar
SiENcE
Party member
Posts: 806
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: [Lib/Lua] Moses 1.4.0

Post by SiENcE »

Nice!

Now I need a löve database :).
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: [Lib/Lua] Moses 2.1.0

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest