C # is a purely functional dictionary

Is there (if not a standard library, or maybe, like the Nuget package) a class suitable for use with C # that provides a purely functional dictionary? That is, when adding or removing a key will return a new dictionary, leaving the original unchanged?

+6
source share
4 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 to copy the original dictionary, manipulations and a new immutable dictionary are applied .

+8

ImmutableDictionary System.Collections.Immutable. https://msdn.microsoft.com/fr-fr/library/dn467181(v=vs.111).aspx

+3
+3

( "", ) #:

https://github.com/louthy/language-ext

:

https://github.com/louthy/language-ext/blob/master/LanguageExt.Core/Map.cs

Disclaimer: I wrote this. But the reasons for the library are to facilitate functional programming in C #. While the accepted answer, ImmutableDictionary is more of an OO style interface (even if it uses immutable semantics).

+1
source

Source: https://habr.com/ru/post/1014449/


All Articles