change an object property in array with ramda

I would do it something like this:

const alter = curry((checked, key, items) => map(
  when(propEq('key', key), assoc('good', checked)),
  items
))

alter('true', '22', items)

This has the advantage of including no free variables (such as checked and name in the original.) The currying can be dropped if you're never going to need partial versions of this.

You can see this in action on the Ramda REPL.


I had to make some assumptions about the value fo checked and name.

let checked = 'true'
let name = '22'

let input = [{name:'name', key:'21',good: 'true'},
{name: 'another name', key:'22',good:'false'}]

const update = R.map(R.ifElse(R.propEq('key', name), R.assoc('good', checked), (item) => item))

console.log(update(input))
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.24.1/ramda.min.js"></script>