Modifying a list value

What happens when we try to modify a list value? As before, copying and sharing kicks in to make the data structure persistent.

Modifying a list value

We changed the fourth node's value from 17 to 97. To keep the persistent view correct, for V1, we had to copy all the nodes on the path leading up to the modified node.

On the other hand, nodes on all other paths are shared. The case with node deletion is also the same.

Modifying a list value

Note that the copying process is the same as the earlier node modification case.

The insertion case would be similar as well. Play ...

Get Learning Functional Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.