I have an object {}
my object may have several nested properties.const myObj = {prop1: {prop2: {prop3: data: null}}}
I need to set data if it's empty
if ( R.isNil(myObj.prop1.prop2.prop3.data))
{
myObj.prop1.prop2.prop3.data = myCurrentDataObj ;
}
This works as long a prop1, prop2 & prop3 exists. But sometimes they don't so I tried
If (R.isNil(myObj.prop1)){ myObj.pro1 = {prop2: {prop3: data: {}}}; }
Do I actually have to explicitly check to see if every property has been defined before I can set data? I was hoping that something like R.lensProp and R.set could solve this for me but if so I haven't figured it out yet.
assocPath
will create intermediate properties I am pretty sure
R.compose(R.defaultTo([0,0]), R.nth(-1))
x = lensPath(['a', *, 'd']);
which would return all d
children of any elements that are children of a
.
a
can be operated on by R.map
callback
helper function I have written below. Could someone please let me know if it exists?const callback = (fn) => (...args) => () => fn(...args)
const obj = {
method: (x, y) => x + y
}
const exists = always(has('method', obj))
const execute = callback(prop('method', obj))('Invoke ', 'Fn')
when(exists, execute)(null)