isn't there a function to sort in place an `IntArr...
# stdlib
e
isn't there a function to sort in place an
IntArray
with a given comparator? I see only
sortedWith
, which returns a new sorted list
1
d
It doesn't seem to exist in stdlib at all, though I agree that it should.
👍 1
m
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
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
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
isn't possible to avoid boxing with an inlined function designed explicitly for primitive arrays?
d
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.