nnmap
v1.0.0
Published
not nil map - Map a function over nullable value
Maintainers
Readme
nnmap
nnmap is a function that takes a function and a value, then call the function with the value only if the value is not nil (undefined or null).
Usage
npm install --save nnmapvar nnmap = require('nnmap');
nnmap(function(a) {
return a + 2;
}, 3);
// > 5
nnmap(function(a) {
return a + 2;
}, undefined);
// > undefined
nnmap(function(a) {
return a + 2;
}, null);
// > nullIt also supports currying
var nnmap = require('nnmap');
[1,2,undefined, 4, 5].map(nnmap(function(a) {
return a + 2;
}));
// > [3, 4, undefined, 6, 7]