January 2019
Beginner
210 pages
4h 47m
English
Immutability refers to the inability to change the value of a variable after a value has been assigned to it. Purely functional programming languages include immutable implementations of common data structures. For example, when we add an element to an array, we are mutating the original array. However, if we use an immutable array and we try to add a new element to it, the original array will not be mutated, and we will add the new item to a copy of it.
The following code snippet declares a class named ImmutableList that demonstrates how it is possible to implement an immutable array:
class ImmutableList<T> { private readonly _list: ReadonlyArray<T>; private _deepCloneItem(item: T) { return JSON.parse(JSON.stringify(item)) as ...Read now
Unlock full access