I have a situation where I want to remove any part of an object tree before flattening and exporting to CSV. Ramda is my choice library for FP in JS, but I noticed the R.omit()
function works at only one level deep of the target object. How can I make it such that I can do the following?
const R = require('ramda');
const obj = {
id: 1,
name: 'me',
audience_sizes: {
fb: 500,
dfp: 2000,
apn: 1800
}
};
console.log(JSON.stringify(R.omit(['id', 'audience_sizes.fb'], obj)));
I would expect the following result:
{"name":"me","audience_sizes":{"dfp":2000, "apn": 1800}}
I have a situation where I want to remove any part of an object tree before flattening and exporting to CSV. Ramda is my choice library for FP in JS, but I noticed the R.omit()
function works at only one level deep of the target object. How can I make it such that I can do the following?
const R = require('ramda');
const obj = {
id: 1,
name: 'me',
audience_sizes: {
fb: 500,
dfp: 2000,
apn: 1800
}
};
console.log(JSON.stringify(R.omit(['id', 'audience_sizes.fb'], obj)));
I would expect the following result:
{"name":"me","audience_sizes":{"dfp":2000, "apn": 1800}}
Share
Improve this question
asked Sep 29, 2018 at 13:53
kennasoftkennasoft
1,5931 gold badge14 silver badges26 bronze badges
2 Answers
Reset to default 9I think Lenses is a more functional way of doing this.
R.over(R.lensProp('audience_sizes'), R.omit(['fb']), R.omit(['id'], obj));
DissocPath look like what you are looking for. Use it or lenses for more plex deep updates.