January 2020
Intermediate to advanced
532 pages
13h 31m
English
In some situations, we may actually want an object to be mutable. The immutability constraint can be removed easily by just adding the mutable keyword in front of the type definition. To make the Stock type mutable, we do the following:
mutable struct Stock <: Equity symbol::String name::Stringend
Now let's try to update the name field in a hypothetical case where Apple changes its company name:

The name field has been updated as we wish. Note that, when a type is declared mutable, all of its fields become mutable. So, in this case, we would be allowed to change the symbol as well. Depending on the situation, such behavior may or ...
Read now
Unlock full access