1 | const { curry } = require('../fp');
|
2 |
|
3 | const either = (fn, fa) => (...arg) => {
|
4 | try {
|
5 | return fn.apply(null, arg);
|
6 | } catch (e) {
|
7 | return typeof fa === 'function' ? fa(e) : fa;
|
8 | }
|
9 | };
|
10 |
|
11 | const fnOrValue = curry((fnOrVal, data) => (typeof fnOrVal === 'function' ? fnOrVal(data) : fnOrVal));
|
12 | const identity = x => x;
|
13 | const not = fn => (...args) => !fn(...args);
|
14 |
|
15 | module.exports = { either, fnOrValue, identity, not };
|