
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Make your javascript code cleaner and more expressive with the power of monads and functional programming.
Make your javascript code cleaner and more expressive with the power of monads and functional programming.
try and catch statements.$ npm install --save monadify
var Monadify = require('monadify'),
n = 1;
function add(n){
return n + 1;
}
//The old way
console.log(add(add(add(n))));
//=> 4
//With Monadify
var nMonad = Monadify(n)
.bind(add)
.bind(add)
.bind(add)
.send(console.log);
//=> 4
//To return the result
var result = nMonad.value();
console.log(result);
//=> 4
Returns a mutation (monad) of the input argument. Optional errorHandler function, which gets called if an error is thrown somewhere down the function chain.
input - The input for the monad. Objects given as input are cloned, to prevent mutation.errorHandler(error) - Callback function to handle error thrown anywhere in the function chain.var nMonad = Monadify(1);
var obj = {},
objMonad = Monadify(obj);
//Objects passed to the constructor are cloned, which means any changes applied to 'obj' are not passed on to objMonad.
obj.a = 'a';
objMonad.send(console.log);
//=> {}
Defaults to throw new Error(e);. Calls the errorHandler function, if present.
var nMonad = Monadify(1, console.log);
// Logs any errors to the console, instead of throwing an error.
var notAFunction = null,
identity = function(n){
return n;
};
nMonad.bind(identity)
.bind(notAFunction)
.bind(identity);
//=> [TypeError: object is not a function]
binds the given function to the current state of the input. Mutates the input into the returned value of bindingFunction.
bindingFunction(input) - Function to be bound to the current state of the input.var nMonad = Monadify(2);
nMonad.bind( n => n*3);
//current state of nMonad is 6
nMonad.send(console.log);
//=> 6
//Monads bound to console.log will subsequently return undefined, since the console.log function has no return value
nMonad.bind(console.log);
//=> 6
// current state of nMonad is undefined
nMonad.send(console.log);
//=> undefined
sends the current state of input to the given function. Does not affect or mutate the input, and retains input state before sending to sentToFunction.
sentToFunction(input) - Function to which the current state of input is passed as an argument. Return value is disregarded.var nMonad = Monadify(2);
nMonad.send( n => n*3);
//current state of nMonad is still 2
nMonad.send(console.log);
//=> 2
//Monads bound to console.log will subsequently return undefined, since the console.log function has no return value
nMonad.send(console.log);
//=> 2
// current state of nMonad is 2
nMonad.send(console.log);
//=> undefined
Returns the current state of input.
var nMonad = Monadify(2);
nMonad.bind( n => n*3);
var n = nMonad.value();
//value of n is 6
console.log(n);
//=> 6
Monadify supports the use of external utility libraries like lodash. It extends their functionality to provide for a great and expressive new way to write code. Lodash functions of the form _.someFunction(operand, argument) can be used with Monadify as someMonad.someFunction(argument).value() (see example).
* This feature is still in development. Contributions are welcome :)
var Monadify = require('monadify'),
_ = require('lodash');
Monadify.use(_);
var nMonad = Monadify([1,2,3]);
nMonad.map(addOne) //Native lodash function => [2,3,4]
.max() //Native lodash function => 4
.bind(addOne) // Monadify bind function => 5
.value(); // => 5
function addOne(n){
return n + 1;
};
FAQs
Make your javascript code cleaner and more expressive with the power of monads and functional programming.
The npm package monadify receives a total of 1 weekly downloads. As such, monadify popularity was classified as not popular.
We found that monadify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.