diff --git a/libraries/stdlib/src/generated/_Ordering.kt b/libraries/stdlib/src/generated/_Ordering.kt index 2a09ac98eb7..f34d1726de3 100644 --- a/libraries/stdlib/src/generated/_Ordering.kt +++ b/libraries/stdlib/src/generated/_Ordering.kt @@ -120,6 +120,7 @@ public fun String.reverse(): String { /** * Returns a sorted list of all elements. */ +deprecated("This method may change its behavior soon. Use sorted() instead.", ReplaceWith("sorted()")) public fun > Iterable.sort(): List { val sortedList = toArrayList() java.util.Collections.sort(sortedList) @@ -129,6 +130,7 @@ public fun > Iterable.sort(): List { /** * Returns a list of all elements, sorted by the specified [comparator]. */ +deprecated("This method may change its behavior soon. Use sortedWith() instead.", ReplaceWith("sortedWith(comparator)")) public fun Array.sortBy(comparator: Comparator): List { val sortedList = toArrayList() java.util.Collections.sort(sortedList, comparator) @@ -138,6 +140,7 @@ public fun Array.sortBy(comparator: Comparator): List { /** * Returns a list of all elements, sorted by the specified [comparator]. */ +deprecated("This method may change its behavior soon. Use sortedWith() instead.", ReplaceWith("sortedWith(comparator)")) public fun Iterable.sortBy(comparator: Comparator): List { val sortedList = toArrayList() java.util.Collections.sort(sortedList, comparator) @@ -147,6 +150,7 @@ public fun Iterable.sortBy(comparator: Comparator): List { /** * Returns a sorted list of all elements, ordered by results of specified [order] function. */ +deprecated("This method may change its behavior soon. Use sortedBy() instead.", ReplaceWith("sortedBy(order)")) public inline fun > Array.sortBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R): List { val sortedList = toArrayList() val sortBy: Comparator = compareBy(order) @@ -157,6 +161,7 @@ public inline fun > Array.sortBy(inlineOptions(Inlin /** * Returns a sorted list of all elements, ordered by results of specified [order] function. */ +deprecated("This method may change its behavior soon. Use sortedBy() instead.", ReplaceWith("sortedBy(order)")) public inline fun > Iterable.sortBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R): List { val sortedList = toArrayList() val sortBy: Comparator = compareBy(order) @@ -167,6 +172,7 @@ public inline fun > Iterable.sortBy(inlineOptions(Inline /** * Returns a sorted list of all elements, in descending order. */ +deprecated("This method may change its behavior soon. Use sortedDescending() instead.", ReplaceWith("sortedDescending()")) public fun > Iterable.sortDescending(): List { val sortedList = toArrayList() java.util.Collections.sort(sortedList, comparator { x, y -> y.compareTo(x) }) @@ -176,6 +182,7 @@ public fun > Iterable.sortDescending(): List { /** * Returns a sorted list of all elements, in descending order by results of specified [order] function. */ +deprecated("This method may change its behavior soon. Use sortedDescendingBy() instead.", ReplaceWith("sortedDescendingBy(order)")) public inline fun > Array.sortDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R): List { val sortedList = toArrayList() val sortBy: Comparator = compareByDescending(order) @@ -186,6 +193,7 @@ public inline fun > Array.sortDescendingBy(inlineOpt /** * Returns a sorted list of all elements, in descending order by results of specified [order] function. */ +deprecated("This method may change its behavior soon. Use sortedDescendingBy() instead.", ReplaceWith("sortedDescendingBy(order)")) public inline fun > Iterable.sortDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R): List { val sortedList = toArrayList() val sortBy: Comparator = compareByDescending(order) @@ -193,9 +201,431 @@ public inline fun > Iterable.sortDescendingBy(inlineOpti return sortedList } +/** + * Returns a list of all elements sorted according to their natural sort order. + */ +public fun > Array.sorted(): List { + val sortedList = toArrayList() + java.util.Collections.sort(sortedList) + return sortedList +} + +/** + * Returns a list of all elements sorted according to their natural sort order. + */ +public fun ByteArray.sorted(): List { + val sortedList = toArrayList() + java.util.Collections.sort(sortedList) + return sortedList +} + +/** + * Returns a list of all elements sorted according to their natural sort order. + */ +public fun CharArray.sorted(): List { + val sortedList = toArrayList() + java.util.Collections.sort(sortedList) + return sortedList +} + +/** + * Returns a list of all elements sorted according to their natural sort order. + */ +public fun DoubleArray.sorted(): List { + val sortedList = toArrayList() + java.util.Collections.sort(sortedList) + return sortedList +} + +/** + * Returns a list of all elements sorted according to their natural sort order. + */ +public fun FloatArray.sorted(): List { + val sortedList = toArrayList() + java.util.Collections.sort(sortedList) + return sortedList +} + +/** + * Returns a list of all elements sorted according to their natural sort order. + */ +public fun IntArray.sorted(): List { + val sortedList = toArrayList() + java.util.Collections.sort(sortedList) + return sortedList +} + +/** + * Returns a list of all elements sorted according to their natural sort order. + */ +public fun LongArray.sorted(): List { + val sortedList = toArrayList() + java.util.Collections.sort(sortedList) + return sortedList +} + +/** + * Returns a list of all elements sorted according to their natural sort order. + */ +public fun ShortArray.sorted(): List { + val sortedList = toArrayList() + java.util.Collections.sort(sortedList) + return sortedList +} + +/** + * Returns a list of all elements sorted according to their natural sort order. + */ +public fun > Iterable.sorted(): List { + val sortedList = toArrayList() + java.util.Collections.sort(sortedList) + return sortedList +} + +/** + * Returns a sequence that yields elements of this sequence sorted according to their natural sort order. + */ +public fun > Sequence.sorted(): Sequence { + return object : Sequence { + override fun iterator(): Iterator { + val sortedList = this@sorted.toArrayList() + java.util.Collections.sort(sortedList) + return sortedList.iterator() + } + } +} + +/** + * Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > Array.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): List { + return sortedWith(compareBy(order)) +} + +/** + * Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > BooleanArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Boolean) -> R?): List { + return sortedWith(compareBy(order)) +} + +/** + * Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > ByteArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Byte) -> R?): List { + return sortedWith(compareBy(order)) +} + +/** + * Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > CharArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Char) -> R?): List { + return sortedWith(compareBy(order)) +} + +/** + * Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > DoubleArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Double) -> R?): List { + return sortedWith(compareBy(order)) +} + +/** + * Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > FloatArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Float) -> R?): List { + return sortedWith(compareBy(order)) +} + +/** + * Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > IntArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Int) -> R?): List { + return sortedWith(compareBy(order)) +} + +/** + * Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > LongArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Long) -> R?): List { + return sortedWith(compareBy(order)) +} + +/** + * Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > ShortArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Short) -> R?): List { + return sortedWith(compareBy(order)) +} + +/** + * Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > Iterable.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): List { + return sortedWith(compareBy(order)) +} + +/** + * Returns a sequence that yields elements of this sequence sorted according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > Sequence.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): Sequence { + return sortedWith(compareBy(order)) +} + +/** + * Returns a list of all elements sorted descending according to their natural sort order. + */ +public fun > Array.sortedDescending(): List { + return sortedWith(comparator { x, y -> y.compareTo(x) }) +} + +/** + * Returns a list of all elements sorted descending according to their natural sort order. + */ +public fun ByteArray.sortedDescending(): List { + return copyOf().apply { sort() }.reverse() +} + +/** + * Returns a list of all elements sorted descending according to their natural sort order. + */ +public fun CharArray.sortedDescending(): List { + return copyOf().apply { sort() }.reverse() +} + +/** + * Returns a list of all elements sorted descending according to their natural sort order. + */ +public fun DoubleArray.sortedDescending(): List { + return copyOf().apply { sort() }.reverse() +} + +/** + * Returns a list of all elements sorted descending according to their natural sort order. + */ +public fun FloatArray.sortedDescending(): List { + return copyOf().apply { sort() }.reverse() +} + +/** + * Returns a list of all elements sorted descending according to their natural sort order. + */ +public fun IntArray.sortedDescending(): List { + return copyOf().apply { sort() }.reverse() +} + +/** + * Returns a list of all elements sorted descending according to their natural sort order. + */ +public fun LongArray.sortedDescending(): List { + return copyOf().apply { sort() }.reverse() +} + +/** + * Returns a list of all elements sorted descending according to their natural sort order. + */ +public fun ShortArray.sortedDescending(): List { + return copyOf().apply { sort() }.reverse() +} + +/** + * Returns a list of all elements sorted descending according to their natural sort order. + */ +public fun > Iterable.sortedDescending(): List { + return sortedWith(comparator { x, y -> y.compareTo(x) }) +} + +/** + * Returns a sequence that yields elements of this sequence sorted descending according to their natural sort order. + */ +public fun > Sequence.sortedDescending(): Sequence { + return sortedWith(comparator { x, y -> y.compareTo(x) }) +} + +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > Array.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > BooleanArray.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Boolean) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > ByteArray.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Byte) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > CharArray.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Char) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > DoubleArray.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Double) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > FloatArray.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Float) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > IntArray.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Int) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > LongArray.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Long) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > ShortArray.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Short) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > Iterable.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a sequence that yields elements of this sequence sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > Sequence.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): Sequence { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a list of all elements sorted according to the specified [comparator]. + */ +public fun Array.sortedWith(comparator: Comparator): List { + val sortedList = toArrayList() + java.util.Collections.sort(sortedList, comparator) + return sortedList +} + +/** + * Returns a list of all elements sorted according to the specified [comparator]. + */ +public fun BooleanArray.sortedWith(comparator: Comparator): List { + val sortedList = toArrayList() + java.util.Collections.sort(sortedList, comparator) + return sortedList +} + +/** + * Returns a list of all elements sorted according to the specified [comparator]. + */ +public fun ByteArray.sortedWith(comparator: Comparator): List { + val sortedList = toArrayList() + java.util.Collections.sort(sortedList, comparator) + return sortedList +} + +/** + * Returns a list of all elements sorted according to the specified [comparator]. + */ +public fun CharArray.sortedWith(comparator: Comparator): List { + val sortedList = toArrayList() + java.util.Collections.sort(sortedList, comparator) + return sortedList +} + +/** + * Returns a list of all elements sorted according to the specified [comparator]. + */ +public fun DoubleArray.sortedWith(comparator: Comparator): List { + val sortedList = toArrayList() + java.util.Collections.sort(sortedList, comparator) + return sortedList +} + +/** + * Returns a list of all elements sorted according to the specified [comparator]. + */ +public fun FloatArray.sortedWith(comparator: Comparator): List { + val sortedList = toArrayList() + java.util.Collections.sort(sortedList, comparator) + return sortedList +} + +/** + * Returns a list of all elements sorted according to the specified [comparator]. + */ +public fun IntArray.sortedWith(comparator: Comparator): List { + val sortedList = toArrayList() + java.util.Collections.sort(sortedList, comparator) + return sortedList +} + +/** + * Returns a list of all elements sorted according to the specified [comparator]. + */ +public fun LongArray.sortedWith(comparator: Comparator): List { + val sortedList = toArrayList() + java.util.Collections.sort(sortedList, comparator) + return sortedList +} + +/** + * Returns a list of all elements sorted according to the specified [comparator]. + */ +public fun ShortArray.sortedWith(comparator: Comparator): List { + val sortedList = toArrayList() + java.util.Collections.sort(sortedList, comparator) + return sortedList +} + +/** + * Returns a list of all elements sorted according to the specified [comparator]. + */ +public fun Iterable.sortedWith(comparator: Comparator): List { + val sortedList = toArrayList() + java.util.Collections.sort(sortedList, comparator) + return sortedList +} + +/** + * Returns a sequence that yields elements of this sequence sorted according to the specified [comparator]. + */ +public fun Sequence.sortedWith(comparator: Comparator): Sequence { + return object : Sequence { + override fun iterator(): Iterator { + val sortedList = this@sortedWith.toArrayList() + java.util.Collections.sort(sortedList, comparator) + return sortedList.iterator() + } + } +} + /** * Returns a sorted list of all elements. */ +deprecated("Use sorted() instead.", ReplaceWith("sorted()")) public fun > Array.toSortedList(): List { val sortedList = toArrayList() java.util.Collections.sort(sortedList) @@ -205,6 +635,7 @@ public fun > Array.toSortedList(): List { /** * Returns a sorted list of all elements. */ +deprecated("Use sorted() instead.", ReplaceWith("sorted()")) public fun BooleanArray.toSortedList(): List { val sortedList = toArrayList() java.util.Collections.sort(sortedList) @@ -214,6 +645,7 @@ public fun BooleanArray.toSortedList(): List { /** * Returns a sorted list of all elements. */ +deprecated("Use sorted() instead.", ReplaceWith("sorted()")) public fun ByteArray.toSortedList(): List { val sortedList = toArrayList() java.util.Collections.sort(sortedList) @@ -223,6 +655,7 @@ public fun ByteArray.toSortedList(): List { /** * Returns a sorted list of all elements. */ +deprecated("Use sorted() instead.", ReplaceWith("sorted()")) public fun CharArray.toSortedList(): List { val sortedList = toArrayList() java.util.Collections.sort(sortedList) @@ -232,6 +665,7 @@ public fun CharArray.toSortedList(): List { /** * Returns a sorted list of all elements. */ +deprecated("Use sorted() instead.", ReplaceWith("sorted()")) public fun DoubleArray.toSortedList(): List { val sortedList = toArrayList() java.util.Collections.sort(sortedList) @@ -241,6 +675,7 @@ public fun DoubleArray.toSortedList(): List { /** * Returns a sorted list of all elements. */ +deprecated("Use sorted() instead.", ReplaceWith("sorted()")) public fun FloatArray.toSortedList(): List { val sortedList = toArrayList() java.util.Collections.sort(sortedList) @@ -250,6 +685,7 @@ public fun FloatArray.toSortedList(): List { /** * Returns a sorted list of all elements. */ +deprecated("Use sorted() instead.", ReplaceWith("sorted()")) public fun IntArray.toSortedList(): List { val sortedList = toArrayList() java.util.Collections.sort(sortedList) @@ -259,6 +695,7 @@ public fun IntArray.toSortedList(): List { /** * Returns a sorted list of all elements. */ +deprecated("Use sorted() instead.", ReplaceWith("sorted()")) public fun LongArray.toSortedList(): List { val sortedList = toArrayList() java.util.Collections.sort(sortedList) @@ -268,6 +705,7 @@ public fun LongArray.toSortedList(): List { /** * Returns a sorted list of all elements. */ +deprecated("Use sorted() instead.", ReplaceWith("sorted()")) public fun ShortArray.toSortedList(): List { val sortedList = toArrayList() java.util.Collections.sort(sortedList) @@ -277,6 +715,7 @@ public fun ShortArray.toSortedList(): List { /** * Returns a sorted list of all elements. */ +deprecated("Use sorted() instead.", ReplaceWith("sorted()")) public fun > Iterable.toSortedList(): List { val sortedList = toArrayList() java.util.Collections.sort(sortedList) @@ -286,6 +725,7 @@ public fun > Iterable.toSortedList(): List { /** * Returns a sorted list of all elements. */ +deprecated("Use asIterable().sorted() instead.", ReplaceWith("asIterable().sorted()")) public fun > Sequence.toSortedList(): List { val sortedList = toArrayList() java.util.Collections.sort(sortedList) @@ -295,6 +735,7 @@ public fun > Sequence.toSortedList(): List { /** * Returns a sorted list of all elements, ordered by results of specified [order] function. */ +deprecated("Use sortedBy(order) instead.", ReplaceWith("sortedBy(order)")) public fun > Array.toSortedListBy(order: (T) -> V): List { val sortedList = toArrayList() val sortBy: Comparator = compareBy(order) @@ -305,6 +746,7 @@ public fun > Array.toSortedListBy(order: (T) -> V): /** * Returns a sorted list of all elements, ordered by results of specified [order] function. */ +deprecated("Use sortedBy(order) instead.", ReplaceWith("sortedBy(order)")) public fun > BooleanArray.toSortedListBy(order: (Boolean) -> V): List { val sortedList = toArrayList() val sortBy: Comparator = compareBy(order) @@ -315,6 +757,7 @@ public fun > BooleanArray.toSortedListBy(order: (Boolean) -> V /** * Returns a sorted list of all elements, ordered by results of specified [order] function. */ +deprecated("Use sortedBy(order) instead.", ReplaceWith("sortedBy(order)")) public fun > ByteArray.toSortedListBy(order: (Byte) -> V): List { val sortedList = toArrayList() val sortBy: Comparator = compareBy(order) @@ -325,6 +768,7 @@ public fun > ByteArray.toSortedListBy(order: (Byte) -> V): Lis /** * Returns a sorted list of all elements, ordered by results of specified [order] function. */ +deprecated("Use sortedBy(order) instead.", ReplaceWith("sortedBy(order)")) public fun > CharArray.toSortedListBy(order: (Char) -> V): List { val sortedList = toArrayList() val sortBy: Comparator = compareBy(order) @@ -335,6 +779,7 @@ public fun > CharArray.toSortedListBy(order: (Char) -> V): Lis /** * Returns a sorted list of all elements, ordered by results of specified [order] function. */ +deprecated("Use sortedBy(order) instead.", ReplaceWith("sortedBy(order)")) public fun > DoubleArray.toSortedListBy(order: (Double) -> V): List { val sortedList = toArrayList() val sortBy: Comparator = compareBy(order) @@ -345,6 +790,7 @@ public fun > DoubleArray.toSortedListBy(order: (Double) -> V): /** * Returns a sorted list of all elements, ordered by results of specified [order] function. */ +deprecated("Use sortedBy(order) instead.", ReplaceWith("sortedBy(order)")) public fun > FloatArray.toSortedListBy(order: (Float) -> V): List { val sortedList = toArrayList() val sortBy: Comparator = compareBy(order) @@ -355,6 +801,7 @@ public fun > FloatArray.toSortedListBy(order: (Float) -> V): L /** * Returns a sorted list of all elements, ordered by results of specified [order] function. */ +deprecated("Use sortedBy(order) instead.", ReplaceWith("sortedBy(order)")) public fun > IntArray.toSortedListBy(order: (Int) -> V): List { val sortedList = toArrayList() val sortBy: Comparator = compareBy(order) @@ -365,6 +812,7 @@ public fun > IntArray.toSortedListBy(order: (Int) -> V): List< /** * Returns a sorted list of all elements, ordered by results of specified [order] function. */ +deprecated("Use sortedBy(order) instead.", ReplaceWith("sortedBy(order)")) public fun > LongArray.toSortedListBy(order: (Long) -> V): List { val sortedList = toArrayList() val sortBy: Comparator = compareBy(order) @@ -375,6 +823,7 @@ public fun > LongArray.toSortedListBy(order: (Long) -> V): Lis /** * Returns a sorted list of all elements, ordered by results of specified [order] function. */ +deprecated("Use sortedBy(order) instead.", ReplaceWith("sortedBy(order)")) public fun > ShortArray.toSortedListBy(order: (Short) -> V): List { val sortedList = toArrayList() val sortBy: Comparator = compareBy(order) @@ -385,6 +834,7 @@ public fun > ShortArray.toSortedListBy(order: (Short) -> V): L /** * Returns a sorted list of all elements, ordered by results of specified [order] function. */ +deprecated("Use sortedBy(order) instead.", ReplaceWith("sortedBy(order)")) public fun > Iterable.toSortedListBy(order: (T) -> V): List { val sortedList = toArrayList() val sortBy: Comparator = compareBy(order) @@ -395,6 +845,7 @@ public fun > Iterable.toSortedListBy(order: (T) -> V): L /** * Returns a sorted list of all elements, ordered by results of specified [order] function. */ +deprecated("Use asIterable().sortedBy(order) instead.", ReplaceWith("asIterable().sortedBy(order)")) public fun > Sequence.toSortedListBy(order: (T) -> V): List { val sortedList = toArrayList() val sortBy: Comparator = compareBy(order) diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt index c81826bfc14..3d7dafb9c9c 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt @@ -38,6 +38,152 @@ fun ordering(): List { exclude(Sequences) } + templates add f("sorted()") { + exclude(Strings) + exclude(PrimitiveType.Boolean) + + doc { + """ + Returns a list of all elements sorted according to their natural sort order. + """ + } + returns("List") + typeParam("T : Comparable") + body { + """ + val sortedList = toArrayList() + java.util.Collections.sort(sortedList) + return sortedList + """ + } + + returns("SELF", Sequences) + doc(Sequences) { + "Returns a sequence that yields elements of this sequence sorted according to their natural sort order." + } + body(Sequences) { + """ + return object : Sequence { + override fun iterator(): Iterator { + val sortedList = this@sorted.toArrayList() + java.util.Collections.sort(sortedList) + return sortedList.iterator() + } + } + """ + } + } + + templates add f("sortedDescending()") { + exclude(Strings) + exclude(PrimitiveType.Boolean) + + doc { + """ + Returns a list of all elements sorted descending according to their natural sort order. + """ + } + returns("List") + typeParam("T : Comparable") + body { + """ + return sortedWith(comparator { x, y -> y.compareTo(x) }) + """ + } + body(ArraysOfPrimitives) { + """ + return copyOf().apply { sort() }.reverse() + """ + } + + returns("SELF", Sequences) + doc(Sequences) { + "Returns a sequence that yields elements of this sequence sorted descending according to their natural sort order." + } + body(Sequences) { + """ + return sortedWith(comparator { x, y -> y.compareTo(x) }) + """ + } + } + + templates add f("sortedWith(comparator: Comparator)") { + exclude(Strings) + returns("List") + doc { + """ + Returns a list of all elements sorted according to the specified [comparator]. + """ + } + body { + """ + val sortedList = toArrayList() + java.util.Collections.sort(sortedList, comparator) + return sortedList + """ + } + + returns("SELF", Sequences) + doc(Sequences) { + "Returns a sequence that yields elements of this sequence sorted according to the specified [comparator]." + } + body(Sequences) { + """ + return object : Sequence { + override fun iterator(): Iterator { + val sortedList = this@sortedWith.toArrayList() + java.util.Collections.sort(sortedList, comparator) + return sortedList.iterator() + } + } + """ + } + } + + templates add f("sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?)") { + exclude(Strings) + inline(true) + returns("List") + typeParam("R : Comparable") + + doc { + """ + Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function. + """ + } + + returns("SELF", Sequences) + doc(Sequences) { + "Returns a sequence that yields elements of this sequence sorted according to natural sort order of the value returned by specified [order] function." + } + + body { + "return sortedWith(compareBy(order))" + } + } + + templates add f("sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?)") { + exclude(Strings) + inline(true) + returns("List") + typeParam("R : Comparable") + + doc { + """ + Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + """ + } + + returns("SELF", Sequences) + doc(Sequences) { + "Returns a sequence that yields elements of this sequence sorted descending according to natural sort order of the value returned by specified [order] function." + } + + body { + "return sortedWith(compareByDescending(order))" + } + } + templates add f("sort()") { doc { """ @@ -46,6 +192,8 @@ fun ordering(): List { } returns("List") typeParam("T : Comparable") + deprecate("This method may change its behavior soon. Use sorted() instead.") + deprecateReplacement("sorted()") body { """ val sortedList = toArrayList() @@ -68,6 +216,11 @@ fun ordering(): List { } returns("List") typeParam("T : Comparable") + deprecate("Use sorted() instead.") + deprecateReplacement("sorted()") + + deprecate("Use asIterable().sorted() instead.", Sequences) + deprecateReplacement("asIterable().sorted()", Sequences) body { """ val sortedList = toArrayList() @@ -85,6 +238,8 @@ fun ordering(): List { Returns a sorted list of all elements, in descending order. """ } + deprecate("This method may change its behavior soon. Use sortedDescending() instead.") + deprecateReplacement("sortedDescending()") returns("List") typeParam("T : Comparable") body { @@ -109,6 +264,8 @@ fun ordering(): List { Returns a sorted list of all elements, ordered by results of specified [order] function. """ } + deprecate("This method may change its behavior soon. Use sortedBy() instead.") + deprecateReplacement("sortedBy(order)") returns("List") typeParam("R : Comparable") body { @@ -132,6 +289,11 @@ fun ordering(): List { """ } returns("List") + deprecate("Use sortedBy(order) instead.") + deprecateReplacement("sortedBy(order)") + + deprecate("Use asIterable().sortedBy(order) instead.", Sequences) + deprecateReplacement("asIterable().sortedBy(order)", Sequences) typeParam("T") typeParam("V : Comparable") body { @@ -154,6 +316,8 @@ fun ordering(): List { Returns a sorted list of all elements, in descending order by results of specified [order] function. """ } + deprecate("This method may change its behavior soon. Use sortedDescendingBy() instead.") + deprecateReplacement("sortedDescendingBy(order)") returns("List") typeParam("R : Comparable") body { @@ -177,6 +341,8 @@ fun ordering(): List { """ } returns("List") + deprecate("This method may change its behavior soon. Use sortedWith() instead.") + deprecateReplacement("sortedWith(comparator)") body { """ val sortedList = toArrayList()