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.

41 lines
1.0 KiB

4 years ago
  1. import _curry2 from "./internal/_curry2.js"; // `Const` is a functor that effectively ignores the function given to `map`.
  2. var Const = function (x) {
  3. return {
  4. value: x,
  5. 'fantasy-land/map': function () {
  6. return this;
  7. }
  8. };
  9. };
  10. /**
  11. * Returns a "view" of the given data structure, determined by the given lens.
  12. * The lens's focus determines which portion of the data structure is visible.
  13. *
  14. * @func
  15. * @memberOf R
  16. * @since v0.16.0
  17. * @category Object
  18. * @typedefn Lens s a = Functor f => (a -> f a) -> s -> f s
  19. * @sig Lens s a -> s -> a
  20. * @param {Lens} lens
  21. * @param {*} x
  22. * @return {*}
  23. * @see R.prop, R.lensIndex, R.lensProp
  24. * @example
  25. *
  26. * const xLens = R.lensProp('x');
  27. *
  28. * R.view(xLens, {x: 1, y: 2}); //=> 1
  29. * R.view(xLens, {x: 4, y: 2}); //=> 4
  30. */
  31. var view =
  32. /*#__PURE__*/
  33. _curry2(function view(lens, x) {
  34. // Using `Const` effectively ignores the setter function of the `lens`,
  35. // leaving the value returned by the getter function unmodified.
  36. return lens(Const)(x).value;
  37. });
  38. export default view;