mirror of
https://github.com/swc-project/swc.git
synced 2024-12-23 05:32:09 +03:00
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
// Loaded from https://deno.land/x/ramda@v0.27.2/source/view.js
|
|
|
|
|
|
import _curry2 from './internal/_curry2.js';
|
|
|
|
|
|
// `Const` is a functor that effectively ignores the function given to `map`.
|
|
var Const = function(x) {
|
|
return {value: x, 'fantasy-land/map': function() { return this; }};
|
|
};
|
|
|
|
/**
|
|
* Returns a "view" of the given data structure, determined by the given lens.
|
|
* The lens's focus determines which portion of the data structure is visible.
|
|
*
|
|
* @func
|
|
* @memberOf R
|
|
* @since v0.16.0
|
|
* @category Object
|
|
* @typedefn Lens s a = Functor f => (a -> f a) -> s -> f s
|
|
* @sig Lens s a -> s -> a
|
|
* @param {Lens} lens
|
|
* @param {*} x
|
|
* @return {*}
|
|
* @see R.set, R.over, R.lens, R.lensIndex, R.lensProp, R.lensPath
|
|
* @example
|
|
*
|
|
* const xLens = R.lensProp('x');
|
|
*
|
|
* R.view(xLens, {x: 1, y: 2}); //=> 1
|
|
* R.view(xLens, {x: 4, y: 2}); //=> 4
|
|
*/
|
|
var view = _curry2(function view(lens, x) {
|
|
// Using `Const` effectively ignores the setter function of the `lens`,
|
|
// leaving the value returned by the getter function unmodified.
|
|
return lens(Const)(x).value;
|
|
});
|
|
export default view;
|