Avoid using negative in descending sorts.
This commit is contained in:
@@ -156,7 +156,7 @@ public inline fun <T, R : Comparable<R>> Iterable<T>.sortBy(inlineOptions(Inline
|
|||||||
*/
|
*/
|
||||||
public fun <T : Comparable<T>> Iterable<T>.sortDescending(): List<T> {
|
public fun <T : Comparable<T>> Iterable<T>.sortDescending(): List<T> {
|
||||||
val sortedList = toArrayList()
|
val sortedList = toArrayList()
|
||||||
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> -x.compareTo(y) }
|
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> y.compareTo(x) }
|
||||||
java.util.Collections.sort(sortedList, sortBy)
|
java.util.Collections.sort(sortedList, sortBy)
|
||||||
return sortedList
|
return sortedList
|
||||||
}
|
}
|
||||||
@@ -166,7 +166,7 @@ public fun <T : Comparable<T>> Iterable<T>.sortDescending(): List<T> {
|
|||||||
*/
|
*/
|
||||||
public inline fun <T, R : Comparable<R>> Array<out T>.sortDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R): List<T> {
|
public inline fun <T, R : Comparable<R>> Array<out T>.sortDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R): List<T> {
|
||||||
val sortedList = toArrayList()
|
val sortedList = toArrayList()
|
||||||
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> -order(x).compareTo(order(y)) }
|
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> order(y).compareTo(order(x)) }
|
||||||
java.util.Collections.sort(sortedList, sortBy)
|
java.util.Collections.sort(sortedList, sortBy)
|
||||||
return sortedList
|
return sortedList
|
||||||
}
|
}
|
||||||
@@ -176,7 +176,7 @@ public inline fun <T, R : Comparable<R>> Array<out T>.sortDescendingBy(inlineOpt
|
|||||||
*/
|
*/
|
||||||
public inline fun <T, R : Comparable<R>> Iterable<T>.sortDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R): List<T> {
|
public inline fun <T, R : Comparable<R>> Iterable<T>.sortDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R): List<T> {
|
||||||
val sortedList = toArrayList()
|
val sortedList = toArrayList()
|
||||||
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> -order(x).compareTo(order(y)) }
|
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> order(y).compareTo(order(x)) }
|
||||||
java.util.Collections.sort(sortedList, sortBy)
|
java.util.Collections.sort(sortedList, sortBy)
|
||||||
return sortedList
|
return sortedList
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ fun ordering(): List<GenericFunction> {
|
|||||||
body {
|
body {
|
||||||
"""
|
"""
|
||||||
val sortedList = toArrayList()
|
val sortedList = toArrayList()
|
||||||
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> -x.compareTo(y) }
|
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> y.compareTo(x) }
|
||||||
java.util.Collections.sort(sortedList, sortBy)
|
java.util.Collections.sort(sortedList, sortBy)
|
||||||
return sortedList
|
return sortedList
|
||||||
"""
|
"""
|
||||||
@@ -150,7 +150,7 @@ fun ordering(): List<GenericFunction> {
|
|||||||
body {
|
body {
|
||||||
"""
|
"""
|
||||||
val sortedList = toArrayList()
|
val sortedList = toArrayList()
|
||||||
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> -order(x).compareTo(order(y)) }
|
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> order(y).compareTo(order(x)) }
|
||||||
java.util.Collections.sort(sortedList, sortBy)
|
java.util.Collections.sort(sortedList, sortBy)
|
||||||
return sortedList
|
return sortedList
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user