You are viewing a single comment's thread from:
RE: Building a fully Immutable Stack in C# - Includes SBD 0.001 puzzle buried in the article :)
That is the nature of immutability, yep, the push returns a new stack with 5 on the head of book, It forks the chain like a fork in blockchain, the 4 2 are common in updated along with the storage infrastructure. I mention this in the notes after that snippet but might not have been clear enough :)
The big mistake people not used to immutability might make is
book.push(5);
thinking book is updated. It has forked as has each call to push. Similar if you make an immutable ATV and change it the original tree is as is and a new copy is built with just the required tree rebuilt :)
If you look after a push/pop I always keep the new returned stack. I am a fan of functional but lisp has too many brackets for me :)