Moses
Moses is a utility library which provides a set of functions acting as shortcuts for common programming tasks,
and support for functional programming.
It aims to extend the built-in Lua table library, facilitate operations on
arrays, lists, collections, objects, through 85 weird, strange, bizarre, odd functions.
Moses was heavily inspired by Underscore.js.
Sample
local _ = require 'moses' -- let's have fun! print('Creating an array of integers') local array = _.range(0,12,3) _.each(array,print) print('Shuffles the array with a random seed') array = _.shuffle(array, os.time()) _.each(array, print) print('Slicing values between 2 and 5 keys') array = _.slice(array,2,5) _.each(array,print) print('Count values by parity') local parityCount = _.countBy(array,function(i,v) return v%2==0 and 'even' or 'odd' end) _.each(parityCount,print)
A possible output would be:
-- Creating an array of integers-- 1 0-- 2 3-- 3 6-- 4 9-- 5 12 -- Shuffles the array with a random seed -- 1 3 -- 2 0 -- 3 6 -- 4 12 -- 5 9 -- Slicing values between 2 and 5 keys -- 1 0 -- 2 6 -- 3 12 -- 4 9 -- Count values by parity -- odd 1 -- even 3
Grab it on Github.
Category: