One of the known problems with data classes is tha...
# stdlib
k
One of the known problems with data classes is that it's easy to get destructured components in the wrong order. It doesn't make it easy when there is inconsistency in the stdlib:
Copy code
for ((index, value) in list.withIndex())  // Correct: the class name is IndexedValue: index first, value second.

val (time, value) = measureTimedValue { } // Wrong! the class name is TimedValue, yet it's actually value first, time second.
😬 2
s
I never spotted that discrepancy! Maybe it helps to explain why I always seem to get those wrong. It's like a USB-A plug, whichever way I try first is always the wrong one
o
It's like a USB-A plug, whichever way I try first is always the wrong one
And like any other binary system, only the 3rd time works!
👍 1
m
even in your example, the class name might be
IndexedValue
. but calling a function thats called
withIndex
, I would assume it returns something with a value first, and then the index. because its a list of values, with index.
2
d
Exactly ^! I've been using
measureTimedValue
and was never bothered by the order of components. I would be more surprised by
withIndex
, although I see now that it's at least consistent with
mapIndexed
.
c
Enabling inlay hints will make this much easier, as the type of each value will be displayed directly in the IDE