Immutable types provide a way to build applications out of a solid foundation of reusable building blocks that are easy to understand and reason about. In some cases, immutable types can also improve memory use (by aggressive sharing) and increase performance (by eliminating time consuming copying and locks).

The design of immutable types means that their externally visible state doesn’t change over their lifetime, making them implicitly safe to share - no need to take a private copy of information to ensure it isn’t changed behind your back. (In some implementations, the internal state of an immutable object might change over time - perhaps caching the result of a time consuming calculation, for example.)

Factory Methods

Saturday, February 18 2017 immutable-types

Our stacks and queues don’t exist in isolation - they have to interoperate with standard framework classes and other domain constructs to be useful. For example, it is extremely useful to have some factory methods to make it easier to construct stacks and queues from existing lists and sequences.

Read more »

Queue Concatenation

Saturday, February 11 2017 immutable-types

If you have a whole sequence of items you want to add to an existing IImmutableQueue<T>, it’s pretty simple to write a loop to add them all. We can make this even easier by writing a simple extension method that handles the looping on our behalf.

Read more »

Complex Immutable Queues

Saturday, February 04 2017 immutable-types

As discussed last time, the solution to our performance problem is to ensure our _inbound stack doesn’t get too large before we reverse it. This means we need to reverse it early; we can’t leave reversal until it’s needed to replace _outbound.

Read more »

The Problem with the Simple Immutable Queue

Saturday, January 28 2017 immutable-types

In my posts Simple Immutable Queues and Enumeration of Immutable Queues I’ve alluded to a nasty flaw that’s waiting to bite. What is that flaw, and why do we need to worry?

Read more »

Enumeration of Immutable Queues

Saturday, January 21 2017 immutable-types

We previously enabled enumeration of our immutable stacks - we should do the same for our immutable queues. Unfortunately, it’s a bit more complicated this time around. (For those looking to the solution to the puzzle posed at the end of my earlier post, you’ll need to wait until next time - but read to the end of this post for a clue.)

Read more »