I have an ImmutableJS structure that looks like this:
let state = fromJS({
// ...
foo: [{
bar: ['id1', 'id2']
},{
bar: ['id2', 'id3']
}]
});
I want to map over foo and for each item, filter the associated bar against another array of ids to exclude (idsToExclude).
I have come up with this:
const idsToExclude = ['id3', 'id4'];
state = {
...state,
foo: state.get('foo').map((i) =>
i.set(['bar'], i.get(['bar']
.filterNot(b => idsToExclude.some(id => id === b))))
};
Is there a better, more idiomatic or terser way?
I ask because this seems quite verbose.