Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# purely functional dictionary

Does there exist (if not in the standard library, then perhaps as a Nuget package) a class, suitable for use from C#, that provides a purely functional dictionary? That is, where adding or removing a key, will return a new dictionary while leaving the original one unchanged?

like image 271
rwallace Avatar asked Jan 26 '17 09:01

rwallace


2 Answers

You are looking for immutable collections, ImmutableDictionary<TKey, TValue> in your case:

https://msdn.microsoft.com/en-us/library/dn467181(v=vs.111).aspx

When you manipulate an immutable dictionary a copy of the original dictionary is made, manipulations applied and a new immutable dictionary is returned.

like image 100
Dmitry Bychenko Avatar answered Oct 16 '22 07:10

Dmitry Bychenko


I found ImmutableDictionary from System.Collections.Immutable. You can find more here https://msdn.microsoft.com/fr-fr/library/dn467181(v=vs.111).aspx

like image 32
Bruno Belmondo Avatar answered Oct 16 '22 06:10

Bruno Belmondo