Using Ramda.js (and lenses), I want to modify the JavaScript object below to change "NAME:VERSION1" to "NAME:VERSION2" for the object that has ID= "/1/B/i".
I want to use a lens because I want to just change one deeply nested value, but otherwise retain the entire structure unchanged.
I don't want to use lensIndex because I never know what order the arrays will be in, so instead, I want to "find" the object in an array by looking for its "id" fields.
Can I do this with lenses, or should I do it a different way?
{
"id": "/1",
"groups": [
{
"id": "/1/A",
"apps": [
{
"id": "/1/A/i",
"more nested data skipped to simplify the example": {}
}
]
},
{
"id": "/1/B",
"apps": [
{ "id": "/1/B/n", "container": {} },
{
"id": "/1/B/i",
"container": {
"docker": {
"image": "NAME:VERSION1",
"otherStuff": {}
}
}
}
]
}
]
}
function lensMatching(pred) { return R.lens( R.find(pred), (newVal, array, other) => { const index = R.findIndex(pred, array); return R.update(index, newVal, array); } ) }
This seems a little easier for me to relate back to the lens documentation. But, am I missing something? – Inflect