https://github.com/zhangchiqing/nnmap
Map a function over nullable value
https://github.com/zhangchiqing/nnmap
curry functional-programming map nullable
Last synced: 4 months ago
JSON representation
Map a function over nullable value
- Host: GitHub
- URL: https://github.com/zhangchiqing/nnmap
- Owner: zhangchiqing
- License: mit
- Created: 2017-06-23T17:42:52.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-25T17:12:04.000Z (over 8 years ago)
- Last Synced: 2025-10-20T06:50:55.340Z (5 months ago)
- Topics: curry, functional-programming, map, nullable
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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).
Type signature:
```haskell
nnmap :: (a -> b) -> a? -> b?
```
### Usage
```
npm install --save nnmap
```
```js
var 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);
// > null
```
It also supports currying
```js
var nnmap = require('nnmap');
[1,2,undefined, 4, 5].map(nnmap(function(a) {
return a + 2;
}));
// > [3, 4, undefined, 6, 7]
```