In functional programming, singly linked lists are extremely popular, because it is easy to reuse sub-lists without allocating any memory or copying values. This means you can add or remove items from one end without any allocation. The F# list is like this.
From what I've read, it sounds like System.Collections.Immutable.ImmutableList<T>
is like an immutable version of System.Collections.Generic.List<T>
, which is an abstraction over arrays. This is more optimized for random access than a linked list, but requires copying the entire list when adding or removing items.
System.Collections.Generic.LinkedList<T>
is a mutable doubly-linked list, which means that either mutation and/or copying is required to add or remove items.
There is no System.Collections.Immutable.ImmutableLinkedList<T>
that I've been able to find.
Is there really no immutable singly-linked list in the System.Collections.Immutable
package? Is using Microsoft.FSharp.Core.List<T>
the best option here?