How to modify an immutable array?
See original GitHub issueWhen using seamless-immutable, what is the recommended way of deriving new values from existing one (when map
and merge
aren’t enough)? Typically, immutable data structures (IDS) have functions that create new IDS derived from them, such as Immutable.js’ aList.push(1, 2)
or Clojure’s updateIn
, assocIn
, dissoc
, etc. In seamless-immutable all array/object mutating functions just throw an error so to create a new IDS I suppose I have to do something like
var newArray; var tmp = Immutable([1,2,3]).asMutable(); tmp.push(4); newArray = Immutable(tmp);
Is that correct? Thank you!
Issue Analytics
- State:
- Created 8 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
Update one of the objects in array, in an immutable way
You can use map to iterate the data and check for the fieldName, if fieldName is cityId then you need to change the...
Read more >Immutable Update Patterns - Redux
Simplifying Immutable Updates with Redux Toolkit Our Redux Toolkit package includes a createReducer utility that uses Immer internally. ...
Read more >All about Immutable Arrays and Objects in JavaScript
Immutable array operations. Push; Unshift; Pop; Shift; Removal and inserting of items; Sort and reverse. Immutable object operations. Modify ...
Read more >Update arrays without mutating the original
Update arrays without mutating the original. ... The concept of not changing values is known as immutability.
Read more >Immutable update patterns - Medium
Examples of native JavaScript values that are mutable include objects, arrays, functions, classes, sets, and maps. 2. An immutable object is ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Keep in mind that the function
map
accepts does receiveindex
, so you can just do:Admittedly more verbose than
mutableArray[indexToUpdate] = newVal
, but in my experience this hasn’t come up all that often.oh, duh. Thanks