mfunc
v0.0.2
Published
Meadhbh's FUNCtional programming library in javascript
Downloads
2
Readme
mfunc
Meadhbh's FUNCtional programming library in javascript
This is a simple module that works with node & browsers to add simple functional programming primitives. These are no better than ones provided by other languages, they're just in a format I like to use.
This module adds:
Function.prototype._$partial( args ) - this function returns a function which pre-applies some number of arguments. Here's an example cribbed from http://dailyjs.com/2012/09/14/functional-programming/ :
Function.prototype._$compose( function ) - this function returns a function which executes the base function (the thing you do the _$compose() on) on the output of the function you pass as a parameter to _$compose(). Example:
Function.prototype._$flip() - returns a function whose arguments are reversed.
Function.prototype._$negate() returns a function whose value is the logical negation of the original.
Array.prototype._$each(function) and Object.prototype._$each(function) Iterates through array calling the function passed for each value passing the element and the index as parameters. 'this' is set as the array (or object).
Array.prototype._$map(function) and Object.prototype._$map(function) Iterates through each element of the array (or object), creating a new array (or object) whose elements are the contents of the original array passed through the function provided.
Object.prototype._$fold( function, base ) Iterates through the object's members combining the output of the value returned from the function provided with the base value specified.