Fix function List<T>.reverse().
For now all iterables (including List) return reversed *copy* of collection. See Problem 3 at https://github.com/JetBrains/kotlin/pull/78#issuecomment-6533534
This commit is contained in:
@@ -245,7 +245,8 @@ public inline fun <in T, C: Collection<in T>> Array<T>.toCollection(result: C) :
|
||||
*/
|
||||
public inline fun <T> Array<T>.reverse() : List<T> {
|
||||
val list = toList()
|
||||
return list.reverse()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/** Copies all elements into a [[LinkedList]] */
|
||||
|
||||
@@ -245,7 +245,8 @@ public inline fun <C: Collection<Boolean>> BooleanArray.toCollection(result: C)
|
||||
*/
|
||||
public inline fun BooleanArray.reverse() : List<Boolean> {
|
||||
val list = toList()
|
||||
return list.reverse()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/** Copies all elements into a [[LinkedList]] */
|
||||
|
||||
@@ -245,7 +245,8 @@ public inline fun <C: Collection<Byte>> ByteArray.toCollection(result: C) : C {
|
||||
*/
|
||||
public inline fun ByteArray.reverse() : List<Byte> {
|
||||
val list = toList()
|
||||
return list.reverse()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/** Copies all elements into a [[LinkedList]] */
|
||||
|
||||
@@ -245,7 +245,8 @@ public inline fun <C: Collection<Char>> CharArray.toCollection(result: C) : C {
|
||||
*/
|
||||
public inline fun CharArray.reverse() : List<Char> {
|
||||
val list = toList()
|
||||
return list.reverse()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/** Copies all elements into a [[LinkedList]] */
|
||||
|
||||
@@ -245,7 +245,8 @@ public inline fun <C: Collection<Double>> DoubleArray.toCollection(result: C) :
|
||||
*/
|
||||
public inline fun DoubleArray.reverse() : List<Double> {
|
||||
val list = toList()
|
||||
return list.reverse()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/** Copies all elements into a [[LinkedList]] */
|
||||
|
||||
@@ -245,7 +245,8 @@ public inline fun <C: Collection<Float>> FloatArray.toCollection(result: C) : C
|
||||
*/
|
||||
public inline fun FloatArray.reverse() : List<Float> {
|
||||
val list = toList()
|
||||
return list.reverse()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/** Copies all elements into a [[LinkedList]] */
|
||||
|
||||
@@ -245,7 +245,8 @@ public inline fun <C: Collection<Int>> IntArray.toCollection(result: C) : C {
|
||||
*/
|
||||
public inline fun IntArray.reverse() : List<Int> {
|
||||
val list = toList()
|
||||
return list.reverse()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/** Copies all elements into a [[LinkedList]] */
|
||||
|
||||
@@ -243,7 +243,8 @@ public inline fun <in T, C: Collection<in T>> java.util.Iterator<T>.toCollection
|
||||
*/
|
||||
public inline fun <T> java.util.Iterator<T>.reverse() : List<T> {
|
||||
val list = toList()
|
||||
return list.reverse()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/** Copies all elements into a [[LinkedList]] */
|
||||
|
||||
@@ -245,7 +245,8 @@ public inline fun <C: Collection<Long>> LongArray.toCollection(result: C) : C {
|
||||
*/
|
||||
public inline fun LongArray.reverse() : List<Long> {
|
||||
val list = toList()
|
||||
return list.reverse()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/** Copies all elements into a [[LinkedList]] */
|
||||
|
||||
@@ -245,7 +245,8 @@ public inline fun <C: Collection<Short>> ShortArray.toCollection(result: C) : C
|
||||
*/
|
||||
public inline fun ShortArray.reverse() : List<Short> {
|
||||
val list = toList()
|
||||
return list.reverse()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/** Copies all elements into a [[LinkedList]] */
|
||||
|
||||
@@ -245,7 +245,8 @@ public inline fun <in T, C: Collection<in T>> Iterable<T>.toCollection(result: C
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.reverse() : List<T> {
|
||||
val list = toList()
|
||||
return list.reverse()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/** Copies all elements into a [[LinkedList]] */
|
||||
|
||||
@@ -235,7 +235,8 @@ public inline fun <in T, C: Collection<in T>> java.lang.Iterable<T>.toCollection
|
||||
*/
|
||||
public inline fun <T> java.lang.Iterable<T>.reverse() : List<T> {
|
||||
val list = toList()
|
||||
return list.reverse()
|
||||
Collections.reverse(list)
|
||||
return list
|
||||
}
|
||||
|
||||
/** Copies all elements into a [[LinkedList]] */
|
||||
|
||||
@@ -40,15 +40,6 @@ public inline fun <in T: java.lang.Comparable<T>> java.lang.Iterable<T>.toSorted
|
||||
|
||||
// List APIs
|
||||
|
||||
/**
|
||||
* Reverses the order the elements into a list
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt reverse
|
||||
*/
|
||||
public inline fun <T> List<T>.reverse() : List<T> {
|
||||
Collections.reverse(this)
|
||||
return this
|
||||
}
|
||||
|
||||
public inline fun <in T: java.lang.Comparable<T>> List<T>.sort() : List<T> {
|
||||
Collections.sort(this)
|
||||
|
||||
Reference in New Issue
Block a user