Difference between revisions of "Moses"
(Created page with "{{#set:Name=Moses}} {{#set:LOVE Version=Any}} {{#set:Description= A utility-belt library for fun and functional programming with Lua}} '''Moses''' is a utility library which pro...") |
m (Added link to the forum thread) |
||
Line 66: | Line 66: | ||
<ul> | <ul> | ||
<li>[https://github.com/Yonaba/Moses/blob/master/moses.lua Source]</li> | <li>[https://github.com/Yonaba/Moses/blob/master/moses.lua Source]</li> | ||
+ | <li>[https://love2d.org/forums/viewtopic.php?f=5&t=10170 Forum thread]</li> | ||
<li>[https://github.com/Yonaba/Moses/downloads HTML Documentation]</li> | <li>[https://github.com/Yonaba/Moses/downloads HTML Documentation]</li> | ||
<li>[https://github.com/Yonaba/Moses/blob/master/docs/moses.md Complete set of samples]</li> | <li>[https://github.com/Yonaba/Moses/blob/master/docs/moses.md Complete set of samples]</li> |
Latest revision as of 12:34, 14 November 2012
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.