Olaf Gottschalk
09/09/2025, 9:41 AMNonEmptyList rather than a List. A byproduct that I do not like that much is that when these elements are used in user output in simple println or logs, the toString() output changes from
List -> [foo, bar]
NonEmptyList -> NonEmptyList(foo, bar)
This is something I wish I could prevent, because more than once I needed to change the logging code to explicitly state "${stuff.joinToString()}" instead of just "$stuff" .
Is it really good and necessary that Arrow's non-empty variants print their own name in their toString() implementations?raulraja
09/09/2025, 10:33 AMNonEmptyList being considered a more restricted version of List and also implementing the List interface should have the same toString as List. Same for all NonEmpty variants with their respective super types.simon.vergauwen
09/09/2025, 10:35 AMTies
09/09/2025, 11:05 AMphldavies
09/09/2025, 11:07 AMphldavies
09/09/2025, 11:09 AMNonEmptyList(myCustomCollection).toString() to result in "MyCustomCollection(a, b c)"Olaf Gottschalk
09/09/2025, 11:10 AMtoString() I would consider this extremely dangerous and wrong. So, we should be fine to remove custom toString() methods for all non empty implementations.phldavies
09/09/2025, 11:11 AMOlaf Gottschalk
09/09/2025, 11:11 AMOlaf Gottschalk
09/09/2025, 11:13 AMphldavies
09/09/2025, 11:15 AMAlejandro Serrano.Mena
09/09/2025, 12:41 PMtoString from the underlying list, or we should do something elseOlaf Gottschalk
09/09/2025, 12:42 PMAlejandro Serrano.Mena
09/09/2025, 12:42 PMAlejandro Serrano.Mena
09/09/2025, 12:43 PMList is just an interface, every type may override their toString as they see fitphldavies
09/09/2025, 12:45 PMAbstractCollection (effectively joinToString(", ", "[", "]") { if (it === this) "(this Collection)" else it.toString() }) but cares needs to be taken to handle this identity within the value classOlaf Gottschalk
09/09/2025, 12:47 PMtoString() of nonEmptyList(...) matches that of listOf(...). I do not expect toString() to always state the exact type like currently. That is for all collections. For a data class, of course, the own type is relevant.Alejandro Serrano.Mena
09/09/2025, 12:49 PMtoString in NonEmptyCollection
โข we can reuse the underlying's value toString
I lean towards the second choice, since it means NotEmpty "invisible", but if you decidee to wrap another type you still get that informationphldavies
09/09/2025, 12:51 PM"MyCustomList(a, b c)" as the .toString() of something that isn't MyCustomList - but the likelihood if that is slim given most collections implement the "standard" (but non-contractual) toString() representationAlejandro Serrano.Mena
09/09/2025, 12:54 PMOlaf Gottschalk
09/09/2025, 1:07 PMTies
09/09/2025, 1:11 PMAlejandro Serrano.Mena
09/09/2025, 1:14 PMTies
09/09/2025, 1:15 PMAlejandro Serrano.Mena
09/09/2025, 1:22 PMphldavies
09/09/2025, 1:32 PMtoNonEmptyList/Set functions, they create and wrap a copy which will almost certainly have the "conventional" toString representation. Only those using wrapAsNonEmptyList/Set functions would potentially expose an underlying non-conventional toString - and to wrap you need to opt in to @PotentiallyUnsafeNonEmptyOperation which should be enough of a deterrent.Olaf Gottschalk
11/10/2025, 9:47 AM