@putout/plugin-apply-maybe
v1.2.1
Published
🐊Putout plugin applies Maybe monad
Maintainers
Readme
@putout/plugin-apply-maybe 
🐊Putout plugin helps with maybe monad. Depends on @putout/declare. Renamed to @putout/plugin-maybe.
Install
npm i @putout/plugin-apply-maybe -DRules
{
"rules": {
"apply-maybe/array": "on",
"apply-maybe/empty-array": "on",
"apply-maybe/fn": "on"
}
}array
❌ Example of incorrect code
const array = isArray(a) ? a : [a];✅ Example of correct code
const maybeArray = (a) => isArray(a) ? a : [a];
const array = maybeArray(a);empty-array
❌ Example of incorrect code
const array = !a ? [] : a;✅ Example of correct code
const maybeArray = (a) => !a ? [] : a;
const array = maybeEmptyArray(a);fn
❌ Example of incorrect code
const fn = isFn(a) ? a : () => {};✅ Example of correct code
const noop = () => {};
const maybeFn = isFn(a) ? a : noop;
const fn = maybeFn(a);noop
❌ Example of incorrect code
const fn = f || (() => {});✅ Example of correct code
const noop = () => {};
const fn = fn || noop;License
MIT
