Open SebastianAigner opened 1 year ago
Just a personal opinion point on this as well: Intuitively, adding elements to a PersistentList
feels much more like a plus
operation than an add
operation (add
is a term that is used often times with mutable collections – and potentially with a return type of Boolean
, whereas plus
provides a hint that the result of the expression would likely be a 'new' collection reference).
It seems like plus
(and the unfortunate plusElement
) would actually already suffice, without an add
function at all.
Adding elements to lists of lists unfortunately comes with long-standing resolution issues for the operator functions: https://youtrack.jetbrains.com/issue/KT-9992
That means the following code works:
but this code doesn't:
From the linked issue, via Roman Elizarov:
The workaround in the standard library collections is using the
plusElement
function. However, no implementation for this function exists for persistent lists, so the implementation returningList<T>
is chosen:This means the APIs between regular read-only lists and persistent lists are quite divergent when it comes to adding elements to collections of collections:
It seems to me that
PersistentList
andPersistentSet
should provide an implementation forplusElement
to help work around this long-standing resolution issue in the same fashion that the standard library collections do.