andand.js
v0.0.3
Published
Maybe Monad for Javascript
Downloads
15
Readme
andand.js
require('andand');
var obj = {
someProp: 42,
someMethod: function() {
return {
anotherProp: 100
}
}
}
obj.andand().someProp
// 42
obj.andand().someMethod().anotherProp
// 100
obj.andand().someMethod().someUnknownProp
// falsy (0)
Tests
npm test
Note: only call methods that you know will exist.
For example,
if ({}.andand().myMethod().andand().someReturnProperty) {
// blah
}
will fail because myMethod is the number 0, which is not a method.
If you are sure that the method exists on an object (even though the object containing it may or may not exist), feel free to call the method in the middle of the chain.
var obj = {
test: function(){
return {
someProp: 42
};
}
};
if (obj.andand().test().andand().someProp == 42) {
//blah
}