mirror of
https://github.com/swc-project/swc.git
synced 2024-12-22 05:01:42 +03:00
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
// Loaded from https://deno.land/x/ramda@v0.27.2/source/ifElse.js
|
|
|
|
|
|
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 }); //=> { count: 2 }
|
|
* incCount({}); //=> { count: 1 }
|
|
*/
|
|
var ifElse = _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;
|