action-debian-package/node_modules/ramda/es/ifElse.js

37 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-03-26 14:37:35 +00:00
import _curry3 from "./internal/_curry3.js";
import curryN from "./curryN.js";
/**
* Creates a function that will process either the `onTrue` or the `onFalse`
* function depending upon the result of the `condition` predicate.
*
* @func
* @memberOf R
* @since v0.8.0
* @category Logic
* @sig (*... -> Boolean) -> (*... -> *) -> (*... -> *) -> (*... -> *)
* @param {Function} condition A predicate function
* @param {Function} onTrue A function to invoke when the `condition` evaluates to a truthy value.
* @param {Function} onFalse A function to invoke when the `condition` evaluates to a falsy value.
* @return {Function} A new function that will process either the `onTrue` or the `onFalse`
* function depending upon the result of the `condition` predicate.
* @see R.unless, R.when, R.cond
* @example
*
* const incCount = R.ifElse(
* R.has('count'),
* R.over(R.lensProp('count'), R.inc),
* R.assoc('count', 1)
* );
* incCount({}); //=> { count: 1 }
* incCount({ count: 1 }); //=> { count: 2 }
*/
var ifElse =
/*#__PURE__*/
_curry3(function ifElse(condition, onTrue, onFalse) {
return curryN(Math.max(condition.length, onTrue.length, onFalse.length), function _ifElse() {
return condition.apply(this, arguments) ? onTrue.apply(this, arguments) : onFalse.apply(this, arguments);
});
});
export default ifElse;