Add upperbound constraint Comparable<T> to toSortedSet() and sortedMapOf()

Provide an overload of toSortedSet() with Comparator<in T> parameter
#KT-10115 Fixed
This commit is contained in:
Ilya Gorbunov
2015-11-20 18:43:00 +03:00
parent f8f257fa44
commit 2ed277a863
6 changed files with 58 additions and 4 deletions
+10 -1
View File
@@ -6274,7 +6274,7 @@ public fun ShortArray.toSet(): Set<Short> {
/**
* Returns a [SortedSet] of all elements.
*/
public fun <T> Array<out T>.toSortedSet(): SortedSet<T> {
public fun <T: Comparable<T>> Array<out T>.toSortedSet(): SortedSet<T> {
return toCollection(TreeSet<T>())
}
@@ -6334,6 +6334,15 @@ public fun ShortArray.toSortedSet(): SortedSet<Short> {
return toCollection(TreeSet<Short>())
}
/**
* Returns a [SortedSet] of all elements.
* Elements in the set returned are sorted according to the given [comparator].
*/
@kotlin.jvm.JvmVersion
public fun <T> Array<out T>.toSortedSet(comparator: Comparator<in T>): SortedSet<T> {
return toCollection(TreeSet<T>(comparator))
}
/**
* Returns a single list of all elements yielded from results of [transform] function being invoked on each element of original array.
*/