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
2
votes
2 answers

Scala immutable Set is mutable?

The docs say: A collection in package scala.collection.immutable is guaranteed to be immutable for everyone. Such a collection will never change after it is created. But I don't get the behavior I would expect from this: scala> var test3 =…
snappymcsnap
  • 2,050
  • 2
  • 29
  • 53
2
votes
3 answers

C# immutable object setter understanding

I have immutable class F1. And i want to change one of it's field. In set method i must return new instance of F1 class with changing. I doesn't understand how i can do this. public class F1 { public readonly int k1; public readonly…
murzagurskiy
  • 1,273
  • 1
  • 20
  • 44
2
votes
2 answers

Is there a with() method inside ImmutableMap?

I am watching the video (https://www.youtube.com/watch?v=ZeO_J2OcHYM) and find that we can initialize the ImmutableMap using the with() method. See below: public static final ImmutableMap ENGLISH_TO_INT = ImmutableMap …
injoy
  • 3,993
  • 10
  • 40
  • 69
2
votes
3 answers

Adding to immutable HashSet

Sorry guys, I recently saw an example in "Programming in Scala", 2nd Edition on page 685, which seemed strange to me: var hashSet: Set[C] = new collection.immutable.HashSet hashSet += elem1 How is it possible to add something an immutable…
Faramarz
  • 121
  • 1
  • 5
2
votes
0 answers

Does System.Collections.Immutable.IImmutableList.Add from Microsoft's Preview of Immutable Collections have a position requirement?

I am implementing an immutable collection, which provides O(1) stack operations and O(log n) list operations. As a result, adding elements to the front is faster than adding elements to the back. Can a valid implementation of…
1
vote
2 answers

Why isn't there an IImmutableArray interface in the .NET Framework?

In the .NET Framework, there are interfaces for immutable dictionaries, lists, queues, sets, stacks. But there is no interface for immutable arrays to be found. Also, immutable arrays are implemented as a struct in contrast to others which are…
aybe
  • 15,516
  • 9
  • 57
  • 105
1
vote
1 answer

Implement Iterable in an immutable LinkedList in Kotlin

I'm trying to understand the functional programming paradigm so I'm playing around with an immutable linked list. I've created a Bag with some utility functions and now I want to iterate through the collection. I want to implement an…
1
vote
0 answers

How to solve error "scala.collection.mutable.WrappedArray$ofRef cannot be cast to [Ljava.lang.String" for unwrapping map in UDF

I get the error above when I apply my UDF, which is defined as followed: import org.apache.spark.sql.functions.typedLit import org.apache.spark.sql.functions.udf def method_name(map:Map[String, Array[String]]):String = { var…
1
vote
1 answer

Supporting collection initialization syntax for immutable collections - init modifiers for methods?

I need to implement an immutable collection which supports collection initialization syntax. The problem is in order to support collection initialization syntax, the collection must provide appropriate public Add() methods. However, if the…
1
vote
0 answers

Enumerate ImmutableSortedSet from an index

ImmutableSortedSet has an IndexOf and I can enumerate the set with a normal for-loop. But according to the source code for ImmutableSortedSet it looks like it have to do a tree-search for every index lookup. If I have thousands of items in the set…
Andreas Zita
  • 7,232
  • 6
  • 54
  • 115
1
vote
2 answers

C# Immutable counter for multiple fields

I have a fairly high throughput on a message counter (tens of thousands per second), and looking for an efficient way of getting the count without putting locks everywhere or ideally not locking on each message count when i am giving an update every…
morleyc
  • 2,169
  • 10
  • 48
  • 108
1
vote
1 answer

How to remove an item from index N with FSharpx's PersistentVector?

I notice that the PersistentVector from FSharpX has no remove at index method. https://fsprojects.github.io/FSharpx.Collections/reference/fsharpx-collections-persistentvector-1.html It has the ability to modify the item at the nth location but no…
bradgonesurfing
  • 30,949
  • 17
  • 114
  • 217
1
vote
1 answer

ImmutableMap.Builder from a HashMap

I have a HashMap of defaults values per keys. I want to convert it to an ImmutableMap.Builder As I have another ImmutableMap which I want to merge and override into the original HashMap. I want to override some of the default pairs and…
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
1
vote
0 answers

How to create a Kotlin list from Java?

How to access methods such as listOf, mapOf and setOf from Java. I'm in a project that doesn't use Kotlin but we want to use the effectively read-only Kotlin collections. Why? Because even when using immutable lists in Java, they have mutator…
caeus
  • 3,084
  • 1
  • 22
  • 36
1
vote
2 answers

How can a Map or List be immutable when we can add or remove elements from them?

Below is a scala code to declare a immutable Map var m:Map[Int,String] = Map(1->"hi",2->"hello") println(m) // Result: Map(1->"hi",2->"hello") Here we are able to add or change the content of Map, then how can we say a map or list…
Abhinav Kumar
  • 210
  • 3
  • 13