javascript - Ramda Js: Setting property on an object using a value from the same object -
using ramda js, need create function can set 1 object property using value of different property on same object. attempt far follows:
var foo = r.set(r.lensprop('bar'), 'foo' + r.prop('foo')); var result = foo({foo:"bar"});
desired result:
{foo:"bar", bar:"foobar"}
actual result:
{foo:"bar", bar: "foofunction f1(a) {... etc"}
clearly i'm misunderstanding here, , insights how approach appreciated.
lenses not fit when value of 1 property depends on value of property. lambda best here:
const foo = o => r.assoc('bar', 'foo' + o.foo, o); foo({foo: 'bar'}); // => {foo: 'bar', bar: 'foobar'}
Comments
Post a Comment