It doesn't seem to exist in stdlib at all, though I agree that it should.
👍 1
m
Michael de Kaste
06/30/2023, 8:30 AM
this is Java functionality: You can't do it with 'primitives', but you can using an typed array:
Copy code
val array = Array(10) { it }
Arrays.sort(array, reverseOrder())
s
Sam
06/30/2023, 8:31 AM
Was just about to say —
IntArray
deals in primitives and Comparators deal in objects, which means there would be a lot of boxing involved if such a method existed
k
Klitos Kyriacou
06/30/2023, 9:35 AM
To avoid boxing, you can use third-party primitive collection libraries (and primitive-type comparators) such as Eclipse Collections and Fastutil (both are JVM only).
e
elect
07/01/2023, 6:58 AM
isn't possible to avoid boxing with an inlined function designed explicitly for primitive arrays?
d
Derek Peirce
07/02/2023, 1:57 AM
Possible if
Comparator
were replaced with a traditional lambda, but I think the sheer amount of code that would have to be inlined for an optimized sorting method would make that a poor candidate for inlining.