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.5 KB
|
Rev | Line | |
---|
[d24f17c] | 1 | var _curry3 =
|
---|
| 2 | /*#__PURE__*/
|
---|
| 3 | require("./internal/_curry3.js");
|
---|
| 4 |
|
---|
| 5 | var curryN =
|
---|
| 6 | /*#__PURE__*/
|
---|
| 7 | require("./curryN.js");
|
---|
| 8 | /**
|
---|
| 9 | * Creates a function that will process either the `onTrue` or the `onFalse`
|
---|
| 10 | * function depending upon the result of the `condition` predicate.
|
---|
| 11 | *
|
---|
| 12 | * Note that `ifElse` takes its arity from the longest of the three functions passed to it.
|
---|
| 13 | *
|
---|
| 14 | * @func
|
---|
| 15 | * @memberOf R
|
---|
| 16 | * @since v0.8.0
|
---|
| 17 | * @category Logic
|
---|
| 18 | * @sig (*... -> Boolean) -> (*... -> *) -> (*... -> *) -> (*... -> *)
|
---|
| 19 | * @param {Function} condition A predicate function
|
---|
| 20 | * @param {Function} onTrue A function to invoke when the `condition` evaluates to a truthy value.
|
---|
| 21 | * @param {Function} onFalse A function to invoke when the `condition` evaluates to a falsy value.
|
---|
| 22 | * @return {Function} A new function that will process either the `onTrue` or the `onFalse`
|
---|
| 23 | * function depending upon the result of the `condition` predicate.
|
---|
| 24 | * @see R.unless, R.when, R.cond
|
---|
| 25 | * @example
|
---|
| 26 | *
|
---|
| 27 | * const incCount = R.ifElse(
|
---|
| 28 | * R.has('count'),
|
---|
| 29 | * R.over(R.lensProp('count'), R.inc),
|
---|
| 30 | * R.assoc('count', 1)
|
---|
| 31 | * );
|
---|
| 32 | * incCount({ count: 1 }); //=> { count: 2 }
|
---|
| 33 | * incCount({}); //=> { count: 1 }
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 | var ifElse =
|
---|
| 38 | /*#__PURE__*/
|
---|
| 39 | _curry3(function ifElse(condition, onTrue, onFalse) {
|
---|
| 40 | return curryN(Math.max(condition.length, onTrue.length, onFalse.length), function _ifElse() {
|
---|
| 41 | return condition.apply(this, arguments) ? onTrue.apply(this, arguments) : onFalse.apply(this, arguments);
|
---|
| 42 | });
|
---|
| 43 | });
|
---|
| 44 |
|
---|
| 45 | module.exports = ifElse; |
---|
Note:
See
TracBrowser
for help on using the repository browser.