Wednesday, February 6, 2019

immutability

Just note to future self:
Work buddy Noah used this immutable.js codepen to help me come up with "how can I modify values in particular Map which is the member of a Set":

const set = Immutable.Set([Immutable.Map({a:'1',b:'foo'}), Immutable.Map({a:'2',b:'bar'}), Immutable.Map({a:'3',b:'baz'})]);
const newSet = set.map(value => 
    value.get('a') === '1' ? value.set('b', 'hello').set('c','woot') : value
)
console.log(JSON.stringify(newSet));

No comments:

Post a Comment