Composing a String from deep properties of an object

In notebook:
Work Notes
Created at:
2018-12-10
Updated:
2018-12-10
Tags:

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