I tried this:
implicit class ArrayExtensions[A](a: Array[A]) {
/**
* Sort a slice [from, until) of this array
*/
def sort(from: Int, until: Int)(implicit cmp: Ordering[A]) = java.util.Arrays.sort(a, from, until, cmp)
}
But, I think I am hitting a bug in the compiler:
[error] found : Array[A]
[error] required: Array[? with Object]
[error] Note: A >: ? with Object, but class Array is invariant in type T.
[error] You may wish to investigate a wildcard type such as `_ >: ? with Object`. (SLS 3.2.10)
[error] def sort(from: Int, until: Int)(implicit cmp: Ordering[A]) = java.util.Arrays.sort(a, from, until, cmp)
How do I get around this?
java.util.Arrays.sortdirectly?java.util.Arraysval a: Array[Int], you can just callArrays.sort(a, from, until)and it will just work. Why do you want to introduceArrayExtensions?scala.util.Sorting.quickSortcode, replacingArraywithmutable.IndexedSeqin it, and sorting withquicksort(a.view(from, until)). See gist.github.com/kolmar/5b891c6058b16757525b I'm not sure why Scala doesn't provide any built-inquickSortmethod for sorting a mutable sequence in place.