Ramda Adjunct 2.5.0

neither.js

  1. import { compose, complement, either } from 'ramda';
  2. /* eslint-disable max-len */
  3. /**
  4. * A function which calls the two provided functions and returns the complement of `||`ing the
  5. * results.
  6. * It returns false if the first function is truth-y and the complement of the second function
  7. * otherwise. Note that this is short-circuited, meaning that the second function will not be
  8. * invoked if the first returns a truth-y value. In short it will return true if neither predicate
  9. * returns true.
  10. *
  11. * In addition to functions, `RA.neither` also accepts any fantasy-land compatible
  12. * applicative functor.
  13. *
  14. * @func neither
  15. * @memberOf RA
  16. * @since {@link https://char0n.github.io/ramda-adjunct/2.3.0|v2.3.0}
  17. * @category Logic
  18. * @sig (*... -> Boolean) -> (*... -> Boolean) -> (*... -> Boolean)
  19. * @param {Function} f A predicate
  20. * @param {Function} g Another predicate
  21. * @return {Function} Returns a function that applies its arguments to `f` and `g` and returns the complement of `||`ing their outputs together.
  22. * @see {@link http://ramdajs.com/docs/#either|either}, {@link http://ramdajs.com/docs/#or|or}
  23. * @example
  24. *
  25. * const gt10 = R.gt(R.__, 10)
  26. * const even = (x) => x % 2 === 0;
  27. * const f = RA.neither(gt10, even);
  28. *
  29. * f(12); //=> false
  30. * f(8); //=> false
  31. * f(11); //=> false
  32. * f(9); //=> true
  33. */
  34. /* eslint-enable max-len */
  35. const neither = compose(complement, either);
  36. export default neither;