Let's assume that we have the following object:
const sample = {
foo: {
tags: [
'aaa', 'bbb'
],
a: 1,
b: 10
},
bar: {
tags: [
'ccc', 'ddd'
],
a: 11,
b: 100
}
}
How can one remove a specific tag value from object sample
using ramda? I have done this
/// Remove tag named 'aaa'
R.map(v => R.assoc('tags', R.without('aaa', v.tags), v), sample)
which achieves the desired result but how can I eliminate the lamda (and the closure created) inside map?
You can R.evolve each object, and use R.without to transform the value of tags
:
const { map, evolve, without } = R const fn = map(evolve({ tags: without('aaa') })) const sample = {"foo":{"tags":["aaa","bbb"],"a":1,"b":10},"bar":{"tags":["ccc","ddd"],"a":11,"b":100}} const result = fn(sample) console.log(result)
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.27.0/ramda.js"></script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.