until.js 855 B

12345678910111213141516171819202122232425262728293031323334
  1. import _curry3 from "./internal/_curry3.js";
  2. /**
  3. * Takes a predicate, a transformation function, and an initial value,
  4. * and returns a value of the same type as the initial value.
  5. * It does so by applying the transformation until the predicate is satisfied,
  6. * at which point it returns the satisfactory value.
  7. *
  8. * @func
  9. * @memberOf R
  10. * @since v0.20.0
  11. * @category Logic
  12. * @sig (a -> Boolean) -> (a -> a) -> a -> a
  13. * @param {Function} pred A predicate function
  14. * @param {Function} fn The iterator function
  15. * @param {*} init Initial value
  16. * @return {*} Final value that satisfies predicate
  17. * @example
  18. *
  19. * R.until(R.gt(R.__, 100), R.multiply(2))(1) // => 128
  20. */
  21. var until =
  22. /*#__PURE__*/
  23. _curry3(function until(pred, fn, init) {
  24. var val = init;
  25. while (!pred(val)) {
  26. val = fn(val);
  27. }
  28. return val;
  29. });
  30. export default until;