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
@@ -1065,10 +1065,19 @@ public fun <T> Iterable<T>.toSet(): Set<T> {
/**
* Returns a [SortedSet] of all elements.
*/
public fun <T> Iterable<T>.toSortedSet(): SortedSet<T> {
public fun <T: Comparable<T>> Iterable<T>.toSortedSet(): SortedSet<T> {
return toCollection(TreeSet<T>())
}
/**
* Returns a [SortedSet] of all elements.
* Elements in the set returned are sorted according to the given [comparator].
*/
@kotlin.jvm.JvmVersion
public fun <T> Iterable<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 collection.
*/