mocoolka-function
Version:
Function lib for function.
27 lines • 1.25 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Tests the final argument by passing it to the given predicate function. If
* the predicate is satisfied, the function will return the result of calling
* the `whenTrueFn` function with the same argument. If the predicate is not
* satisfied, the argument is returned as is.
*
* @since v0.1.0
* @param {Function} pred A predicate function
* @param {Function} whenTrueFn A function to invoke when the `condition`
* evaluates to a truthy value.
* @param {*} x An object to test with the `pred` function and
* pass to `whenTrueFn` if necessary.
* @return {*} Either `x` or the result of applying `x` to `whenTrueFn`.
* @example
*
* // truncate :: String -> String
* var truncate = R.when(
* R.propSatisfies(R.gt(R.__, 10), 'length'),
* R.pipe(R.take(10), R.append('…'), R.join(''))
* );
* truncate('12345'); //=> '12345'
* truncate('0123456789ABC'); //=> '0123456789…'
*/
var when = function (pred, whenTrueFn, x) { return pred(x) ? whenTrueFn(x) : x; };
exports.default = when;
//# sourceMappingURL=when.js.map