Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficient, Immutable, Extensible Collections for .NET [duplicate]

It seems to me there is an extreme lack of safe, immutable collection types for .NET, in particular BCL but I've not seen much work done outside either. Do anyone have any pointers to a (preferably) production quality, fast, immutable collections library for .NET. A fast list type is essential. I'm not yet prepared to switch to F#.

*Edit: Note to searchers, this is being rolled into the BCL soon: .NET immutable collections

like image 815
Bent Rasmussen Avatar asked Aug 14 '10 21:08

Bent Rasmussen


People also ask

What is the advantage of having immutable collections and when we have to use the immutable collections?

Less heap space: The space required to store a collection data is very less as compared with the traditional approach in earlier versions of java. Faster access to data: As the overhead to store data and wrap into Collections. unmodifiable is reduced, now data access becomes faster.

What are immutable collections?

The common use case for the immutable methods is a collection that is initialized from known values, and that never changes. Also consider using these methods if your data changes infrequently. For optimal performance, the immutable collections store a data set that never changes.

Which data types are immutable in C#?

Numbers, strings and null can only be used as const fields, which are truly immutable. Readonly is not truly immutable because it allows writing only once.

What is ImmutableList?

ImmutableList, as suggested by the name, is a type of List which is immutable. It means that the content of the List are fixed or constant after declaration, that is, they are read-only. If any attempt made to add, delete and update elements in the List, UnsupportedOperationException is thrown.


1 Answers

You might want to take a look at the Microsoft.FSharp.Collections namespace in the FSharp.Core assembly. You do not have to program in F# to make use of these types.

Keep in mind that the names will be different when used from outside F#. For example, the Map in F# is known as FSharpMap from C#.

like image 199
Rich Avatar answered Nov 08 '22 16:11

Rich