It's not quite clear to me what you want. But here's are two possible solution, based on my best guess:
const makeArrays = R.evolve({products: R.map(R.values)})
const state = {"products": {"newValues": {"1": {"name": "Product 1", "product_id": 1}, "2": {"name": "Product 2", "product_id": 2}}, "newValuescat": {"61": {"category_id": 61, "name": "category name"}}}}
console.log(makeArrays(state))
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.js"></script>
From the inside out, here's what it does: R.values
is much the same as Object.values
, taking an object, thought of as a list of key-value pairs, and returning a list of just the values. Passing that to R.map
and supplying that the products
object, we map over the elements in products
, replacing them with the call to R.values
in each one. Finally R.evolve
takes a specification object that supplies functions to run on each of its keys, and transforms and object using those functions.
My second version is similar, still using map(values)
, but using a slightly more standard tool than Ramda's evolve
, known as lenses:
const makeArrays = R.over(R.lensProp('products'), R.map(R.values))
const state = {"products": {"newValues": {"1": {"name": "Product 1", "product_id": 1}, "2": {"name": "Product 2", "product_id": 2}}, "newValuescat": {"61": {"category_id": 61, "name": "category name"}}}}
console.log(makeArrays(state))
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.js"></script>
A Lens lets you focus attention on one part of a data structure, leaving the rest intact. You can access the property with R.view
, mutate the property with R.set
, or adjust it with R.over
. There are several functions that produce lenses. Here we use R.lensProp
, which focuses attention on a named property of an object.
Lenses are a more widely recognized tool in the functional programming world than Ramda's more proprietary, evolve
. But they are designed for different things. Lenses are meant to focus on a specific part of a structure, but to do anything you want with it, where evolve
lets you adjust many parts of a structure, but doesn't offer plain access that lenses do. Because you want only to adjust a single property, either approach will work here.