1 | import { useWith, curry, compose } from 'ramda';
|
---|
2 | import list from './list';
|
---|
3 | import isTruthy from './isTruthy';
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * Takes a combining predicate and a list of functions and returns a function which will map the
|
---|
7 | * arguments it receives to the list of functions and returns the result of passing the values
|
---|
8 | * returned from each function to the combining predicate. A combining predicate is a function that
|
---|
9 | * combines a list of Boolean values into a single Boolean value, such as `R.any` or `R.all`. It
|
---|
10 | * will test each value using `RA.isTruthy`, meaning the functions don't necessarily have to be
|
---|
11 | * predicates.
|
---|
12 | *
|
---|
13 | * The function returned is curried to the number of functions supplied, and if called with more
|
---|
14 | * arguments than functions, any remaining arguments are passed in to the combining predicate
|
---|
15 | * untouched.
|
---|
16 | *
|
---|
17 | * @func argsPass
|
---|
18 | * @memberOf RA
|
---|
19 | * @since {@link https://char0n.github.io/ramda-adjunct/2.7.0|v2.7.0}
|
---|
20 | * @category Logic
|
---|
21 | * @sig ((* -> Boolean) -> [*] -> Boolean) -> [(* -> Boolean), ...] -> (*...) -> Boolean
|
---|
22 | * @param {Function} combiningPredicate The predicate used to combine the values returned from the
|
---|
23 | * list of functions
|
---|
24 | * @param {Array} functions List of functions
|
---|
25 | * @return {boolean} Returns the combined result of mapping arguments to functions
|
---|
26 | * @example
|
---|
27 | *
|
---|
28 | * RA.argsPass(R.all, [RA.isArray, RA.isBoolean, RA.isString])([], false, 'abc') //=> true
|
---|
29 | * RA.argsPass(R.all, [RA.isArray, RA.isBoolean, RA.isString])([], false, 1) //=> false
|
---|
30 | * RA.argsPass(R.any, [RA.isArray, RA.isBoolean, RA.isString])({}, 1, 'abc') //=> true
|
---|
31 | * RA.argsPass(R.any, [RA.isArray, RA.isBoolean, RA.isString])({}, 1, false) //=> false
|
---|
32 | * RA.argsPass(R.none, [RA.isArray, RA.isBoolean, RA.isString])({}, 1, false) //=> true
|
---|
33 | * RA.argsPass(R.none, [RA.isArray, RA.isBoolean, RA.isString])({}, 1, 'abc') //=> false
|
---|
34 | */
|
---|
35 | var argsPass = curry(function (combiningPredicate, predicates) {
|
---|
36 | return useWith(compose(combiningPredicate(isTruthy), list), predicates);
|
---|
37 | });
|
---|
38 | export default argsPass; |
---|