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
|
Rev | Line | |
---|
[d24f17c] | 1 | import _curry1 from "./internal/_curry1.js";
|
---|
| 2 | import curryN from "./curryN.js";
|
---|
| 3 | import max from "./max.js";
|
---|
| 4 | import pluck from "./pluck.js";
|
---|
| 5 | import reduce from "./reduce.js";
|
---|
| 6 | /**
|
---|
| 7 | * Takes a list of predicates and returns a predicate that returns true for a
|
---|
| 8 | * given list of arguments if every one of the provided predicates is satisfied
|
---|
| 9 | * by those arguments.
|
---|
| 10 | *
|
---|
| 11 | * The function returned is a curried function whose arity matches that of the
|
---|
| 12 | * highest-arity predicate.
|
---|
| 13 | *
|
---|
| 14 | * @func
|
---|
| 15 | * @memberOf R
|
---|
| 16 | * @since v0.9.0
|
---|
| 17 | * @category Logic
|
---|
| 18 | * @sig [(*... -> Boolean)] -> (*... -> Boolean)
|
---|
| 19 | * @param {Array} predicates An array of predicates to check
|
---|
| 20 | * @return {Function} The combined predicate
|
---|
| 21 | * @see R.anyPass, R.both
|
---|
| 22 | * @example
|
---|
| 23 | *
|
---|
| 24 | * const isQueen = R.propEq('Q', 'rank');
|
---|
| 25 | * const isSpade = R.propEq('♠︎', 'suit');
|
---|
| 26 | * const isQueenOfSpades = R.allPass([isQueen, isSpade]);
|
---|
| 27 | *
|
---|
| 28 | * isQueenOfSpades({rank: 'Q', suit: '♣︎'}); //=> false
|
---|
| 29 | * isQueenOfSpades({rank: 'Q', suit: '♠︎'}); //=> true
|
---|
| 30 | */
|
---|
| 31 |
|
---|
| 32 | var allPass =
|
---|
| 33 | /*#__PURE__*/
|
---|
| 34 | _curry1(function allPass(preds) {
|
---|
| 35 | return curryN(reduce(max, 0, pluck('length', preds)), function () {
|
---|
| 36 | var idx = 0;
|
---|
| 37 | var len = preds.length;
|
---|
| 38 |
|
---|
| 39 | while (idx < len) {
|
---|
| 40 | if (!preds[idx].apply(this, arguments)) {
|
---|
| 41 | return false;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | idx += 1;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | return true;
|
---|
| 48 | });
|
---|
| 49 | });
|
---|
| 50 |
|
---|
| 51 | export default allPass; |
---|
Note:
See
TracBrowser
for help on using the repository browser.