🐊Putout plugin helps with maybe
monad.
npm i @putout/plugin-maybe -D
{
"rules": {
"maybe/array": "on",
"maybe/empty-array": "on",
"maybe/fn": "on",
"maybe/noop": "on",
"maybe/declare": "on"
}
}
const array = isArray(a) ? a : [a];
const maybeArray = (a) => isArray(a) ? a : [a];
const array = maybeArray(a);
const array = !a ? [] : a;
const maybeArray = (a) => !a ? [] : a;
const array = maybeEmptyArray(a);
const isFn = (a) => typeof a === 'function';
const fn = isFn(a) ? a : () => {};
const isFn = (a) => typeof a === 'function';
const noop = () => {};
const maybeFn = isFn(a) ? a : noop;
const fn = maybeFn(a);
const fn = f || (() => {});
const noop = () => {};
const fn = fn || noop;
const fn = maybeFn(f);
const isFn = (a) => typeof a === 'function';
const noop = () => {};
const maybeFn = isFn(a) ? a : noop;
const fn = maybeFn(f);
MIT