Hi! I do not understand the behaviour of <https://...
# arrow
t
Hi! I do not understand the behaviour of https://arrow-kt.io/docs/apidocs/arrow-core/arrow.core/kotlin.collections.-iterable/compare-to.html (0.13.1). The following applies:
Copy code
listOf(1, 0, 0) > listOf(0, 1, 1) == true
listOf(0, 1, 0) > listOf(1, 0, 1) == false
Looking at the implementation I understand how this is computed but I believe this is a bug. I am not quite sure, since I do not understand how the compareTo-operator should work on lists but right now the whole outcome is determined by the comparison of the elements at index 0. And If two values at the same position are equal then the whole outcome is determined by the comparison at the next index unless the equality occurred at the end. At least to me it seems like it was not intended to work this way.
y
It is definitely intended to work this way, just like how a string comparator checks index 0 first then index 1 etc. Basically, it assumes that the first element is the biggest, and so if they're equal then it checks the next one etc. What behaviour are you trying to accomplish?
t
I did not try to accomplish anything. I saw it, got curious and tried it out. But like I said: I wasn't sure how a list comparison should work. Now I understand. Thank you.
j
I if it just compares the first it's a bug. The correct behavior is a zipped fold which compares element wise, if they are both equal and list a is longer we choose that as greater, otherwise list b
Will check later how it's actually implemented
The idea is: we zip two lists together with align (to handle different sizes) then compare each element and fold over the comparison. The first unequal result determines the final result
👌 1