1 | var _curry3 =
|
2 | /*#__PURE__*/
|
3 | require("./internal/_curry3");
|
4 | /**
|
5 | * Tests the final argument by passing it to the given predicate function. If
|
6 | * the predicate is satisfied, the function will return the result of calling
|
7 | * the `whenTrueFn` function with the same argument. If the predicate is not
|
8 | * satisfied, the argument is returned as is.
|
9 | *
|
10 | * @func
|
11 | * @memberOf R
|
12 | * @since v0.18.0
|
13 | * @category Logic
|
14 | * @sig (a -> Boolean) -> (a -> a) -> a -> a
|
15 | * @param {Function} pred A predicate function
|
16 | * @param {Function} whenTrueFn A function to invoke when the `condition`
|
17 | * evaluates to a truthy value.
|
18 | * @param {*} x An object to test with the `pred` function and
|
19 | * pass to `whenTrueFn` if necessary.
|
20 | * @return {*} Either `x` or the result of applying `x` to `whenTrueFn`.
|
21 | * @see R.ifElse, R.unless, R.cond
|
22 | * @example
|
23 | *
|
24 | * // truncate :: String -> String
|
25 | * const truncate = R.when(
|
26 | * R.propSatisfies(R.gt(R.__, 10), 'length'),
|
27 | * R.pipe(R.take(10), R.append('…'), R.join(''))
|
28 | * );
|
29 | * truncate('12345'); //=> '12345'
|
30 | * truncate('0123456789ABC'); //=> '0123456789…'
|
31 | */
|
32 |
|
33 |
|
34 | var when =
|
35 | /*#__PURE__*/
|
36 | _curry3(function when(pred, whenTrueFn, x) {
|
37 | return pred(x) ? whenTrueFn(x) : x;
|
38 | });
|
39 |
|
40 | module.exports = when; |
\ | No newline at end of file |