immutable-collections

(imutable collection is mutable) returns true in Kotlin

我的梦境 提交于 2021-01-27 12:55:18
问题 Why this is happening in Kotlin: val list: List<Int> = 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 MutableCollection<Int>).add(4) // this results to java.lang.UnsupportedOperationException } list is MutableCollection returns true that shows Kotlin Immutable collection objects implements MutableCollection interface but instead of changing items in collection it throws

Is it possible to write an immutable doubly linked list?

元气小坏坏 提交于 2021-01-27 06:16:34
问题 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 the list A :: B, at time of construction, A needs to know about B, but B also needs to know about A. I've been doing this in Scala, so I'm not sure if it's specific to Scala, but I can't picture how that would work. I'm not looking for a substitute

Should one prefer ImmutableDictionary, or ImmutableSortedDictionary?

大兔子大兔子 提交于 2020-01-24 02:42:04
问题 I have heard that the .NET System.Collections.Immutable collections are implemented as balanced binary trees in order to satisfy their immutability constraints, even collections which traditionally model hash tables like Dictionary , by using the integral value of GetHashCode as a sort key. If I have a type for which it is cheap to generate a hash code, and for which is cheap to compare (e.g. string or int ), and I don't care about the sorted-ness of my collection, would it make sense to

Java 8 collector for Guava Immutable Table

 ̄綄美尐妖づ 提交于 2020-01-01 07:04:15
问题 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 a way to achieve it? Current implementation (as suggested by Bohemian): How about using parallel stream ? Is there any concurrency issues in the below code? With Parallel stream i an getting "NullPointerException at index 1800" on tableBuilder

ReadonlyCollection, are the objects immutable?

限于喜欢 提交于 2019-12-20 02:27:28
问题 I'm trying using ReadOnlyCollection to make object immutable, I want the property of object are immutable. public ReadOnlyCollection<FooObject> MyReadOnlyList { get { return new ReadOnlyCollection<FooObject>(_myDataList); } } But I little confused. I tried to change the property of the object in to MyReadOnlyList using a foreach and ... I can change value property, is it correct? I understood ReadOnlyCollection set an add level to make the object immutable. 回答1: The fact that

Where is ImmutableArray?

一笑奈何 提交于 2019-12-10 14:26:14
问题 Why does ImmutableArray seem to not be there in Microsoft Immutable Collections NuGet package version 1.0.34? 回答1: ImmutableArray is not present in your version of the library. As you can see in the version history, the release notes for 1.1.20 mention "Re-included ImmutableArray<T>" You can find the explanation for why ImmutableArray was absent from the 1.0 version on the .NET blog, in this announcement. (In short - the Roslyn team had a noticeable performance hit when they tried to use that

Difference between ImmutableArray<T> and ImmutableList<T>

强颜欢笑 提交于 2019-12-09 07:35:17
问题 What is difference between ImmutableArray<T> and ImmutableList<T> , and where would it be best to use each? 回答1: I think you are asking where to use both. This blog will help otherwise some good points are mentioned here. Use immutable array when: Updating the data is rare or the number of elements is quite small (<16) You need to be able to iterate over the data in performance critical sections You have many instances of immutable collections and you can’t afford keeping the data in trees

Java 8 collector for Guava Immutable Table

孤人 提交于 2019-12-03 21:15:29
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 a way to achieve it? Current implementation (as suggested by Bohemian): How about using parallel stream ? Is there any concurrency issues in the below code? With Parallel stream i an getting "NullPointerException at index 1800" on tableBuilder.build(), but works fine with stream. ImmutableTable<Integer, String, Boolean> buildData() { // list of 4

Difference between ImmutableArray<T> and ImmutableList<T>

对着背影说爱祢 提交于 2019-12-03 09:30:01
What is difference between ImmutableArray<T> and ImmutableList<T> , and where would it be best to use each? I think you are asking where to use both. This blog will help otherwise some good points are mentioned here. Use immutable array when: Updating the data is rare or the number of elements is quite small (<16) You need to be able to iterate over the data in performance critical sections You have many instances of immutable collections and you can’t afford keeping the data in trees Use immutable list when: Updating the data is common or the number of elements isn't expected to be small

Do I have to include all System.Collections.Immutable dependencies?

别说谁变了你拦得住时间么 提交于 2019-11-27 17:14:25
问题 I just switched from (an older) Microsoft.Bcl.Immutable NuGet package to System.Collections.Immutable and was surprised to find all these new package dependencies in my project: System.Collections System.Diagnostics.Debug System.Globalization System.Linq System.Resources.ResourceManager System.Runtime System.Runtime.Extensions System.Threading They are listed as dependencies of the NuGet package, so they have a right to be there, yet they are obviously also already installed on my PC and my