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)
I would push for ADTs over currying for sure. Point free without static types can make things harder to read until used to it. It's really nice if your team is into it, but otherwise I think it's best used sparingly. There are certain places where currying makes a ton of sense (DI is often one of those cases).
I can't tell you how often I see a good use for Maybe or Either. They come up everywhere, and are especially helpful in dynamically typed code.
(arg1, arg2) => async () => { ... }