Composing a String from deep properties of an object
A use case: I have a big object that holds somewhere a title
element and somewhere else parent
element and I want to join these properties together to create a path string from them.
The R.evolve
, then R.pick
seems like a good solution to prepare a simple object that holds just the values that I need for my string:
const myObj = {
note: {
meta: {
title: 'thetitle'
}
},
nbook: {
uuid: 'notebook'
},
redundant: {
foo: 'bar'
}
}
const transformations = {
note: R.path(['meta', 'title']),
nbook: R.prop('uuid')
}
const createPath = R.compose(
R.join('/'),
R.values,
R.pick(['nbook', 'note']),
R.evolve(transformations)
)
// createPath(myObj) => notebook/title