You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.1 KiB

4 years ago
  1. import _curry3 from "./internal/_curry3.js";
  2. /**
  3. * Tests the final argument by passing it to the given predicate function. If
  4. * the predicate is not satisfied, the function will return the result of
  5. * calling the `whenFalseFn` function with the same argument. If the predicate
  6. * is satisfied, the argument is returned as is.
  7. *
  8. * @func
  9. * @memberOf R
  10. * @since v0.18.0
  11. * @category Logic
  12. * @sig (a -> Boolean) -> (a -> a) -> a -> a
  13. * @param {Function} pred A predicate function
  14. * @param {Function} whenFalseFn A function to invoke when the `pred` evaluates
  15. * to a falsy value.
  16. * @param {*} x An object to test with the `pred` function and
  17. * pass to `whenFalseFn` if necessary.
  18. * @return {*} Either `x` or the result of applying `x` to `whenFalseFn`.
  19. * @see R.ifElse, R.when, R.cond
  20. * @example
  21. *
  22. * let safeInc = R.unless(R.isNil, R.inc);
  23. * safeInc(null); //=> null
  24. * safeInc(1); //=> 2
  25. */
  26. var unless =
  27. /*#__PURE__*/
  28. _curry3(function unless(pred, whenFalseFn, x) {
  29. return pred(x) ? x : whenFalseFn(x);
  30. });
  31. export default unless;