KT-3823 Standard sort function requires MutableIterable by no reason

#KT-3823 Fixed
This commit is contained in:
Nikolay Krasko
2013-07-30 01:18:05 +04:00
parent b205e10b31
commit 2520f11bdc
2 changed files with 13 additions and 1 deletions
@@ -64,7 +64,7 @@ public fun <T> Iterable<T>.containsItem(item : T) : Boolean {
}
public inline fun <T: Comparable<T>> MutableIterable<T>.sort() : List<T> {
public inline fun <T: Comparable<T>> Iterable<T>.sort() : List<T> {
val list = toCollection(ArrayList<T>())
java.util.Collections.sort(list)
return list
+12
View File
@@ -402,6 +402,18 @@ class CollectionTest {
// assertFalse(IterableWrapper(linkedList<Int>()).contains(15))
}
test fun sortForMutableIterable() {
val list : MutableIterable<Int> = arrayList<Int>(2, 3, 1)
expect(arrayList(1, 2, 3)) { list.sort() }
expect(arrayList(2, 3, 1)) { list }
}
test fun sortForIterable() {
val list : Iterable<Int> = listOf(2, 3, 1)
expect(arrayList(1, 2, 3)) { list.sort() }
expect(arrayList(2, 3, 1)) { list }
}
class IterableWrapper<T>(collection : Iterable<T>) : Iterable<T> {
private val collection = collection