source: node_modules/ramda/es/when.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1import _curry3 from "./internal/_curry3.js";
2/**
3 * Tests the final argument by passing it to the given predicate function. If
4 * the predicate is satisfied, the function will return the result of calling
5 * the `whenTrueFn` function with the same argument. If the predicate is not
6 * satisfied, the argument is returned as is.
7 *
8 * @func
9 * @memberOf R
10 * @since v0.18.0
11 * @category Logic
12 * @sig (a -> Boolean) -> (a -> b) -> a -> a | b
13 * @param {Function} pred A predicate function
14 * @param {Function} whenTrueFn A function to invoke when the `condition`
15 * evaluates to a truthy value.
16 * @param {*} x An object to test with the `pred` function and
17 * pass to `whenTrueFn` if necessary.
18 * @return {*} Either `x` or the result of applying `x` to `whenTrueFn`.
19 * @see R.ifElse, R.unless, R.cond
20 * @example
21 *
22 * // truncate :: String -> String
23 * const truncate = R.when(
24 * R.propSatisfies(R.gt(R.__, 10), 'length'),
25 * R.pipe(R.take(10), R.append('…'), R.join(''))
26 * );
27 * truncate('12345'); //=> '12345'
28 * truncate('0123456789ABC'); //=> '0123456789…'
29 */
30
31var when =
32/*#__PURE__*/
33_curry3(function when(pred, whenTrueFn, x) {
34 return pred(x) ? whenTrueFn(x) : x;
35});
36
37export default when;
Note: See TracBrowser for help on using the repository browser.