ecmascript-immutable-data-structures icon indicating copy to clipboard operation
ecmascript-immutable-data-structures copied to clipboard

Ability to set multiple values at once

Open RReverser opened this issue 9 years ago • 4 comments

When you need to add multiple values, there is little sense in doing separate operations (and also creating intermediate objects) like:

const a = ImmutableMap([['x', 1], ['y', 2]]);
const b = a.set('z', 3).set('t', 4);

It would be nice to have .extend method that would allow to do things like:

const a = ImmutableMap([['x', 1], ['y', 2]]);
const b = a.extend({z: 3, t: 4}); // or a.extend(#{z: 3, t: 4});

RReverser avatar May 06 '15 09:05 RReverser

I believe this is something that can be handled by a merge operation. extend is surely confusing and hugely overloaded term.

skrat avatar Oct 05 '15 14:10 skrat

@skrat merge also doesn't exist at the moment. I don't care whether it will be called merge, extend or assign, the functionality is what's interesting.

RReverser avatar Oct 05 '15 16:10 RReverser

I believe ideas is that spread operator will handle that:

const b = #{ ...a, z: 3, t: 4};

Gozala avatar Oct 05 '15 19:10 Gozala

@Gozala: That applies to Record, not ImmutableMap.

ckknight avatar Oct 20 '15 04:10 ckknight