set.js 827 B

123456789101112131415161718192021222324252627282930313233
  1. import _curry3 from "./internal/_curry3.js";
  2. import always from "./always.js";
  3. import over from "./over.js";
  4. /**
  5. * Returns the result of "setting" the portion of the given data structure
  6. * focused by the given lens to the given value.
  7. *
  8. * @func
  9. * @memberOf R
  10. * @since v0.16.0
  11. * @category Object
  12. * @typedefn Lens s a = Functor f => (a -> f a) -> s -> f s
  13. * @sig Lens s a -> a -> s -> s
  14. * @param {Lens} lens
  15. * @param {*} v
  16. * @param {*} x
  17. * @return {*}
  18. * @see R.view, R.over, R.lens, R.lensIndex, R.lensProp, R.lensPath
  19. * @example
  20. *
  21. * const xLens = R.lensProp('x');
  22. *
  23. * R.set(xLens, 4, {x: 1, y: 2}); //=> {x: 4, y: 2}
  24. * R.set(xLens, 8, {x: 1, y: 2}); //=> {x: 8, y: 2}
  25. */
  26. var set =
  27. /*#__PURE__*/
  28. _curry3(function set(lens, v, x) {
  29. return over(lens, always(v), x);
  30. });
  31. export default set;