Questions tagged [immutable-collections]

Immutable Collections is a library containing immutable data structures created by Microsoft for .NET.

Immutable Collections is a library containing immutable data structures created by Microsoft for .NET.

Related tags

93 questions
3
votes
1 answer

(imutable collection is mutable) returns true in Kotlin

Why this is happening in Kotlin: val list: List = listOf(1, 2, 3)// Immutable list if(list is MutableCollection<*>){// why this "if" condition is true? println("is mutable")// this line is printed (list as…
ygngy
  • 3,630
  • 2
  • 18
  • 29
3
votes
0 answers

Should ImmutableSortedSet throw an ArgumentNullException on Contains(null)

I have spent two days chasing down an evil bug. I narrowed down the problem with this test case demonstrating different behavior for different collection classes that implement the same interface. Specifically Contains(null) throws a…
bradgonesurfing
  • 30,949
  • 17
  • 114
  • 217
3
votes
3 answers

Java 8 collector for Guava Immutable Table

Use case: Process list of string via method which returns ImmutableTable of type {R,C,V}. For instance ImmutableTable of {Integer,String,Boolean} process(String item){...} Collect the result i.e, merge all results and return ImmutableTable. Is there…
sidss
  • 923
  • 1
  • 12
  • 20
3
votes
3 answers

Creating an ImmutableList of a type that is unknown at compile-time

Given a Collection whose type T is only known in runtime (not at compile time), I would like to generate an ImmutableList. The method I would like to create may like like: var immutableList = CreateImmutableList(originalList, type); where…
SuperJMN
  • 13,110
  • 16
  • 86
  • 185
3
votes
0 answers

Why is ImmutableDictionary implementing IDictionary?

It looks like a weird design choice, because a Dictionary and an ImmutableDictionary are quite different write-wise. (Read-wise, they both implement IReadOnlyDictionary, which is fine*) In fact, the current implementation of IDictionary
3
votes
1 answer

Looking for usable immutable bool array in C#

I have a class which has an bool array member. If I modify an element of this array, a new modified copy of the instance should be created. Sounds like a perfect opportunity for using an Immutable type. Googling around showed that Microsoft provides…
Johannes
  • 1,599
  • 1
  • 10
  • 10
3
votes
3 answers

Make list/collection of objects with public properties truly read-only

I have following problem. Let's say there is a public Class1 defined like this: public class Class1 { public string pr1 { get; set; } public string pr2 { get; set; } public Class1() { } } I'm not allowed to modify class…
plukow
  • 31
  • 3
2
votes
1 answer

How to cast ImmutableArray to ImmutablyArray and vice versa in C#?

I know it's not possible to cast derived lists (why not is nicely explained here), but what about ImmutableArrays as they cannot be changed casting should be valid, right? I would expect this to work: class Animal {} class Dog : Animal…
DomenPigeon
  • 618
  • 7
  • 12
2
votes
2 answers

What is the difference between ImmutableArray.As and ImmutableArray.CastArray methods?

I'm trying to understand the exact difference between the 3 following methods of the ImmutableArray struct: the static method ImmutableArray.CastUp the instance method ImmutableArray.As the instance method…
Enrico Massone
  • 6,464
  • 1
  • 28
  • 56
2
votes
2 answers

Guava - Collect values extracted from two Optionals into an ImmutableSet

I am looking to avoid multiple if-else conditions. Is there a more concise way of writing the below code? private Set getValues(Optional one, Optional two) { if (one.isPresent() && two.isPresent()) { return…
Punter Vicky
  • 15,954
  • 56
  • 188
  • 315
2
votes
2 answers

Constructing immutable dictionary with inner immutable dictionary

I have the following dictionary and wish to make it immutable; var dict = ConcurrentDictionary> I then call var immmutableDict = dict.ToImmutableDictionary(); However this would still give the internal…
morleyc
  • 2,169
  • 10
  • 48
  • 108
2
votes
3 answers

How to create a fast-call delegate that has parameters and return type of private types, speeding up DynamicInvoke

I'm struggling with creating a call to the private ImmutableDictionary.Add, which allows me to utilize the KeyCollisionBehavior for finer control (the Add method only throws when key and value are different, I need it to throw always). I can get…
Abel
  • 56,041
  • 24
  • 146
  • 247
2
votes
0 answers

How to use ImmutableList<> instead of List<> in Entity Framework 6

In my project, we are using either Entity Framework 6 and the Microsoft's System.Collections.Immutable types nuget package. We aim to be able to do a query into the Database with EF and the data returned be immutable by default. Since we have…
Sassa
  • 1,673
  • 2
  • 16
  • 30
2
votes
3 answers

How to update value in a nested Immutable map

I am new to immutable.js and trying to figure out a way to update a nested map Here is my object let state = OrderedMap({ 'name': Map({ id: 'name', hint: 'Search by name', value: '' }), 'job': Map({ id: 'job', hint: 'Search by job title',…
kishore
  • 719
  • 9
  • 29
2
votes
1 answer

C# ImmutableStack Performance

I have a need to use the System.Collections.Immutable ImmutableStack in my code however I have noticed that there has been some performance hit since using it. I was wondering if there is an alternative to this that could provide a better…
ODotN
  • 145
  • 7