source: node_modules/ramda-adjunct/src/argsPass.js@ d24f17c

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

Initial commit

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