forked from waja/action-debian-package
37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
import _curry3 from "./internal/_curry3.js";
|
|
/**
|
|
* 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.
|
|
*
|
|
* @func
|
|
* @memberOf R
|
|
* @since v0.18.0
|
|
* @category Logic
|
|
* @sig (a -> Boolean) -> (a -> a) -> a -> a
|
|
* @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`.
|
|
* @see R.ifElse, R.unless, R.cond
|
|
* @example
|
|
*
|
|
* // truncate :: String -> String
|
|
* const 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 =
|
|
/*#__PURE__*/
|
|
_curry3(function when(pred, whenTrueFn, x) {
|
|
return pred(x) ? whenTrueFn(x) : x;
|
|
});
|
|
|
|
export default when; |