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
6
votes
1 answer

Is it possible to write an immutable doubly linked list?

I feel a little stupid for asking this, but I'm currently learning functional programming and completed an exercise on creating singly linked lists and it just got me thinking, is it even possible to create an immutable doubly linked list? Suppose…
Andy
  • 3,228
  • 8
  • 40
  • 65
6
votes
1 answer

RemoveAll from map in F#

C#: In C# I have something like this: IImmutableDictionary map = new Dictionary { {"K1", "V1"}, {"K2", "V2"}, {"K3", "V3"}, }.ToImmutableDictionary(); IEnumerable keys = new[] {"K1,K3"}; map =…
George Mamaladze
  • 7,593
  • 2
  • 36
  • 52
6
votes
3 answers

ReadonlyCollection, are the objects immutable?

I'm trying using ReadOnlyCollection to make object immutable, I want the property of object are immutable. public ReadOnlyCollection MyReadOnlyList { get { return new ReadOnlyCollection(_myDataList); …
lunatic84
  • 300
  • 4
  • 12
6
votes
2 answers

Where is ImmutableArray?

Why does ImmutableArray seem to not be there in Microsoft Immutable Collections NuGet package version 1.0.34?
thomius
  • 784
  • 2
  • 9
  • 21
5
votes
1 answer

Why does ImmutableList have complexity O(logN) in its add method?

I think a new ImmutableList of N+1 items is created. Thus its complexity should be O(N).
Tian Xiao
  • 239
  • 2
  • 7
5
votes
3 answers

JAVA: ImmutableSet as List

I currently get returned an ImmutableSet from a function call (getFeatures()) and due to the structure of the rest of my code to be executed later on- it would be much easier to change this to a List. I have tried to cast it which produces a runtime…
GregH
  • 5,125
  • 8
  • 55
  • 109
5
votes
2 answers

ImmutableHashSet .Contains returns false

I have a list (to be precise ImmutableHashSet from System.Collections.Immutable) of base items and try to call the following code _baseList.Contains(derivedItem) but this returns false. Even though the following code lines all return…
Rand Random
  • 7,300
  • 10
  • 40
  • 88
5
votes
1 answer

BCL Immutable Collections: equality is non-symmetric

Since immutable data strucutures are first-class values we can compare them for equality or order as we do with any other values. But things became complicated in BCL immutable collections preview because every immutable collection can be…
4
votes
3 answers

Adding items to an ImmutableList inside an ImmutableDictionary

I can't seem to figure out how add items to an ImmutableList inside of an ImmutableDictionary. I have the following variable: ImmutableDictionary> _attributes = ImmutableDictionary
jscarle
  • 1,045
  • 9
  • 17
4
votes
4 answers

Update immutable object without breaking immutability

how can I get updated immutable object from another immutable object without breaking the immutability in a good way. Something similar to how things are achieved in Scala or how they are achieved in Immutables library. How can I achieve something…
3
votes
4 answers

ImmutableArray how to use properly

I'm trying to create an array of constant values that CANNOT NEVER change. I try something like this.... public class ColItem { public string Header { get; set; } // real header name in ENG/CHI public string HeaderKey { get;…
Imp
  • 39
  • 6
3
votes
1 answer

Is it possible to use Immutable.Collections on C# Interactive?

I am using the C# Interactive window (i.e. the REPL) on Visual Studio 2019, with latest updates. I want to use immutable collections but can't get them to work. (I have no problem using them in a compiled C# project). Strangely, if I enter (into C#…
3
votes
4 answers

How to Create Immutable Class with List Element in class

Immutable Class with List package com.text.immutable; import java.util.Collections; import java.util.List; // An immutable class Student public final class Student { final String name; final int regNo; final List courses; …
Sadina Khatun
  • 1,136
  • 2
  • 18
  • 27
3
votes
2 answers

Why does Online Python Tutor present this immutable integer as two different integers graphically?

In Fluent Python, By Luciano Ramalho, Chapter 8, Copies Are Shallow by Default, there is an example: >>> listOne = [3, [55, 44], (7, 8, 9)] >>> listTwo = list(listOne) >>> listTwo [3, [55, 44], (7, 8, 9)] >>> listTwo == listOne True >>> listTwo is…
Yu Zhang
  • 2,037
  • 6
  • 28
  • 42
3
votes
1 answer

What is a better way to solve this exercise in more Immutable way?

I am trying to solve a problem on HackerRank. I am trying to solve this problem in more functional way (using immutability). I have attempted a solution but I am not fully confident about it. Here’s a link to the…