Is there a .net library with a constant immutable Vector class (as shown in Clojure / Scala)?

I spent a good hour searching Google and can find various immutable lists of .NET, Sets and Maps. However, I could not find a constant constant vector.

Something like Scala immutable Vector is what I need (and I find it similar in Clojure). It must be called from the C # library.

Is there such a thing in Microsoft-land?

+5
source share
2 answers

ClojureCLR. Clojure CLR/DLR. , , . Clojure\Clojure\Lib , PersistentVector.cs

.

+2

.NET( #) FSharpX.Collections, NuGet.

:

// Create an empty PersistentVector and add some elements
PersistentVector<string> vector =
    PersistentVector<string>.Empty()
        .Conj("hello")
        .Conj("world")
        .Conj("!");

PersistentVector<string> vector2 = vector.Conj("!!!").Update(0,"hi");

Console.WriteLine(vector2[0]); // hi
Console.WriteLine(vector[0]);  // hello
Console.WriteLine(vector2[3]); // !!!

Console.WriteLine(vector.Length);  // 3
Console.WriteLine(vector2.Length); // 4

// remove the last element from a PersistentVector
PersistentVector<string> vector3 = vector2.Initial;

Console.WriteLine(vector3.Length); // 3
+1

All Articles