An immutable function changes data without changing the value it receives. Instead, it returns a new version, leaving the original available for comparison, debugging, or restoration. section 4.8
Suppose a library system must change Watchmen’s publication year. An immutable update follows the information path to that field, returns updated library data, and preserves the previous version. Structural sharing keeps unchanged parts common between versions rather than copying everything. section 4.2
A safe immutable-update design follows these rules:
- Use immutable functions for every data manipulation; do not use the native hash map setter. section 4.4
- Separate calculation from commit: calculate a new state version without side effects, then move the system reference forward. section 4.8
- Expect shared data to remain safe only when all updates use immutable operations. section 4.4
Updating a nested field
var nextLibraryData = _.set(libraryData, ["catalog", "booksByIsbn", "978-1779501127", "publicationYear"], 1986);
