This commit is contained in:
Dawid Dziurla 2020-03-26 15:37:35 +01:00
parent d9becc67b6
commit 9308795b8b
No known key found for this signature in database
GPG key ID: 7B6D8368172E9B0B
964 changed files with 104265 additions and 16 deletions

68
node_modules/ramda/src/cond.js generated vendored Normal file
View file

@ -0,0 +1,68 @@
var _arity =
/*#__PURE__*/
require("./internal/_arity");
var _curry1 =
/*#__PURE__*/
require("./internal/_curry1");
var map =
/*#__PURE__*/
require("./map");
var max =
/*#__PURE__*/
require("./max");
var reduce =
/*#__PURE__*/
require("./reduce");
/**
* Returns a function, `fn`, which encapsulates `if/else, if/else, ...` logic.
* `R.cond` takes a list of [predicate, transformer] pairs. All of the arguments
* to `fn` are applied to each of the predicates in turn until one returns a
* "truthy" value, at which point `fn` returns the result of applying its
* arguments to the corresponding transformer. If none of the predicates
* matches, `fn` returns undefined.
*
* @func
* @memberOf R
* @since v0.6.0
* @category Logic
* @sig [[(*... -> Boolean),(*... -> *)]] -> (*... -> *)
* @param {Array} pairs A list of [predicate, transformer]
* @return {Function}
* @see R.ifElse, R.unless, R.when
* @example
*
* const fn = R.cond([
* [R.equals(0), R.always('water freezes at 0°C')],
* [R.equals(100), R.always('water boils at 100°C')],
* [R.T, temp => 'nothing special happens at ' + temp + '°C']
* ]);
* fn(0); //=> 'water freezes at 0°C'
* fn(50); //=> 'nothing special happens at 50°C'
* fn(100); //=> 'water boils at 100°C'
*/
var cond =
/*#__PURE__*/
_curry1(function cond(pairs) {
var arity = reduce(max, 0, map(function (pair) {
return pair[0].length;
}, pairs));
return _arity(arity, function () {
var idx = 0;
while (idx < pairs.length) {
if (pairs[idx][0].apply(this, arguments)) {
return pairs[idx][1].apply(this, arguments);
}
idx += 1;
}
});
});
module.exports = cond;