stdlib: Add mutableList.sort function

This commit is contained in:
Ilya Matveev
2017-02-27 16:23:19 +03:00
committed by ilmat192
parent 135025ff8d
commit 73adb8524d
@@ -258,17 +258,17 @@ private fun MutableCollection<*>.retainNothing(): Boolean {
/** /**
* Sorts elements in the list in-place according to their natural sort order. * Sorts elements in the list in-place according to their natural sort order.
*/ */
@FixmeSorting public fun <T : Comparable<T>> MutableList<T>.sort(): Unit = sortWith(Comparator<T> { a: T, b: T -> a.compareTo(b) })
public fun <T : Comparable<T>> MutableList<T>.sort(): Unit {
TODO()
//if (size > 1) java.util.Collections.sort(this)
}
/** /**
* Sorts elements in the list in-place according to the order specified with [comparator]. * Sorts elements in the list in-place according to the order specified with [comparator].
*/ */
@FixmeSorting
public fun <T> MutableList<T>.sortWith(comparator: Comparator<in T>): Unit { public fun <T> MutableList<T>.sortWith(comparator: Comparator<in T>): Unit {
TODO() if (size > 1) {
//if (size > 1) java.util.Collections.sort(this, comparator) val it = listIterator()
for (v in toTypedArray().apply { sortWith(comparator) }) {
it.next()
it.set(v)
}
}
} }