Ramda Adjunct 2.33.0

argsPass.js

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