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
@@ -44,11 +44,26 @@ fun snapshots(): List<GenericFunction> {
templates add f("toSortedSet()") {
deprecate(Strings) { forBinaryCompatibility }
include(CharSequences, Strings)
typeParam("T: Comparable<T>")
doc { f -> "Returns a [SortedSet] of all ${f.element}s." }
returns("SortedSet<T>")
body { "return toCollection(TreeSet<T>())" }
}
templates add f("toSortedSet(comparator: Comparator<in T>)") {
only(Iterables, ArraysOfObjects, Sequences)
jvmOnly(true)
doc { f ->
"""
Returns a [SortedSet] of all ${f.element}s.
Elements in the set returned are sorted according to the given [comparator].
"""
}
returns("SortedSet<T>")
body { "return toCollection(TreeSet<T>(comparator))" }
}
templates add f("toArrayList()") {
doc { f -> "Returns an [ArrayList] of all ${f.element}s." }
returns("ArrayList<T>")