How to use the lensProp function from ramda

Find comprehensive JavaScript ramda.lensProp code examples handpicked from public code repositorys.

ramda.lensProp creates a lens for a given property name.

42
43
44
45
46
47
48
49
50
51
const l_0 = R.lensIndex(0)
const l_1 = R.lensIndex(1)
const l_50 = R.lensIndex(50)
const l_x = R.lensProp('x')
const l_y = R.lensProp('y')
const l_z = R.lensProp('z')
const l_0_x_0_y = R.compose(
  l_0,
  l_x,
  l_0,
fork icon41
star icon901
watch icon29

+ 11 other calls in file

156
157
158
159
160
161
162
163
164
165
var getMonth = function getMonth(project) {
  return moment(project.starred_at).format('MMMM');
};

var languageLens = function languageLens(project) {
  return R.lensProp(project.repo.language);
};
var dateLens = function dateLens(project) {
  return R.lensProp(getMonth(project));
};
fork icon6
star icon57
watch icon4

+ 3 other calls in file

How does ramda.lensProp work?

ramda.lensProp is a function in the Ramda library that creates a lens that focuses on a specific property of an object.

The returned lens can be used to read, write or transform the property value in a safe and functional way, without directly mutating the object.

The lensProp function takes a string representing the property name and returns a lens object that can be used in Ramda's view, set, over, and other lens-related functions.

-1
fork icon2
star icon5
watch icon0

+ 3 other calls in file

21
22
23
24
25
26
27
28
29
30
31
32
33


const logShuffle = (s) =>
  log('shuffling %d describe blocks in "%s"',
    s.suites.length, s.title)


const suitesLens = R.lensProp('suites')
const shuffleSuites = R.over(suitesLens, _.shuffle)
const shuffleNestedSuites = R.over(suitesLens, R.map(shuffleDescribes))


function shuffleTests (suite) {
fork icon1
star icon8
watch icon0

Ai Example

1
2
3
4
const person = { name: "John", age: 32 };
const ageLens = R.lensProp("age");
const newPerson = R.set(ageLens, 33, person); // { name: 'John', age: 33 }
const age = R.view(ageLens, person); // 32

In this example, ramda.lensProp is used to create a lens for the age property of an object. This lens can be used to get, set or modify the value of the property. In this case, it is used to update the age of a person object and to get the age of the original person object.

72
73
74
75
76
77
78
79
80
81
82
83
    widthMin: 100,
  }
}


// Shorthand accessor for modifying rungSpecs
const RUNG_SPECS_LENS = R.lensProp('rungSpecs')


// --------------------------------------
// internal functions
// --------------------------------------
fork icon0
star icon0
watch icon0

+ 252 other calls in file

4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
* @param {*} x
* @return {*}
* @see R.prop, R.lensIndex, R.lensProp
* @example
*
*      var xLens = R.lensProp('x');
*
*      R.set(xLens, 4, {x: 1, y: 2});  //=> {x: 4, y: 2}
*      R.set(xLens, 8, {x: 1, y: 2});  //=> {x: 8, y: 2}
*/
fork icon0
star icon0
watch icon0

+ 53 other calls in file

15
16
17
18
19
20
21
22
23
24
25
26
27
28


const privateFields = R.concat(COMMON_PRIVATE_FIELDS, USER_PRIVATE_FIELDS);


let KNOWN_TEST_CLOUD_USER_DATA;


const birthdayLens = R.lensProp('birthday');


describe('cloudUserCtrl.getAllCloudUsers', () => {
  beforeAll(done => {
    converter.fromFile(path.resolve(__dirname, '../../../../run/env/test/seedData/coreDb/cloudUsers.csv'), (err, data) => {
fork icon0
star icon0
watch icon0

+ 2 other calls in file

8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
* @param {String} k
* @return {Lens}
* @see R.view, R.set, R.over
* @example
*
*      const xLens = R.lensProp('x');
*
*      R.view(xLens, {x: 1, y: 2});            //=> 1
*      R.set(xLens, 4, {x: 1, y: 2});          //=> {x: 4, y: 2}
*      R.over(xLens, R.negate, {x: 1, y: 2});  //=> {x: -1, y: 2}
fork icon0
star icon0
watch icon2

+ 11 other calls in file

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29


State.getId = R.path(['state', 'id']);


State.eq = R.pathEq(['state', 'id']);


State.lens = R.lensProp('state');


Object.freeze(State);


///// Player
fork icon0
star icon0
watch icon0

+ 3 other calls in file

18
19
20
21
22
23
24
25
26
27
28
29
// --------------------------------------
// constants
// --------------------------------------


// Accessor for dim
const DIM_LENS = R.lensProp('dim')


// --------------------------------------
// internal functions
// --------------------------------------
fork icon0
star icon0
watch icon0

Other functions in ramda

Sorted by popularity

function icon

ramda.clone is the most popular function in ramda (30311 examples)