:mega::mega::mega: A quick survey about immutable ...
# stdlib
i
📣📣📣 A quick survey about immutable collections. 📣📣📣 If you had the immutable collections in Kotlin, what would you use them for? We need to gather some use cases to better understand which implementations of immutable collections should be provided/should be default.
h
I'm confused. Doesn't
listOf(…)
,
mapOf(…)
,
setOf(…)
already produce immutable collections?
Thanks @kevinmost for the explanation: Those are returning read-only views of mutable collections.
k
Yeah, for example,
list1 + list2
creates a new
ArrayList
and does
addAll
twice, once with each list. With immutable collections, presumably there'd be a
ConcatenatedList
implementation that just returns a view of the two underlying collections because it's guaranteed they'd never be mutated
h
I think that's how Scala does it?
k
Yes, I believe so. I'm not sure how interop with Java works there, if it does at all
j
Id use them to enforce isolation of components, if I call into user code and want to assert that it is "pure" that it either returns positive changes or fails hard.
r
Yes, that is how Scala and Clojure do it. They were inspired by the book
Purely Functional  Data Structures
by Okasaki https://www.cs.cmu.edu/~rwh/theses/okasaki.pdf
d
In my case, I need to concat a bunch of 'immutable' lists to pass as xmlrpc params... which means a lot of repetitive default param lists being concated to the changing ones... also I needed to concat a list into that list [1, [2, 3]] from [1] and [2,3]...