plus: do not generate ambiguos overloads.
This commit is contained in:
@@ -635,24 +635,20 @@ public fun <T> Set<T>.plus(array: Array<out T>): Set<T> {
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of the original collection and then all elements of the given [collection].
|
||||
*/
|
||||
public fun <T> Collection<T>.plus(collection: Collection<T>): List<T> {
|
||||
val result = ArrayList<T>(this.size() + collection.size())
|
||||
result.addAll(this)
|
||||
result.addAll(collection)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of the original collection and then all elements of the given [collection].
|
||||
*/
|
||||
public fun <T> Collection<T>.plus(collection: Iterable<T>): List<T> {
|
||||
if (collection is Collection) return this.plus(collection)
|
||||
val result = ArrayList<T>(this)
|
||||
result.addAll(collection)
|
||||
return result
|
||||
if (collection is Collection) {
|
||||
val result = ArrayList<T>(this.size() + collection.size())
|
||||
result.addAll(this)
|
||||
result.addAll(collection)
|
||||
return result
|
||||
} else {
|
||||
val result = ArrayList<T>(this)
|
||||
result.addAll(collection)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -52,7 +52,7 @@ fun generators(): List<GenericFunction> {
|
||||
only(Iterables, Collections, Sets, Sequences)
|
||||
doc { "Returns a list containing all elements of the original collection and then all elements of the given [collection]." }
|
||||
returns("List<T>")
|
||||
returns("SELF", ArraysOfObjects, ArraysOfPrimitives, Sets, Sequences)
|
||||
returns("SELF", Sets, Sequences)
|
||||
body {
|
||||
"""
|
||||
if (this is Collection) return this.plus(collection)
|
||||
@@ -64,14 +64,19 @@ fun generators(): List<GenericFunction> {
|
||||
}
|
||||
body(Collections) {
|
||||
"""
|
||||
if (collection is Collection) return this.plus(collection)
|
||||
val result = ArrayList<T>(this)
|
||||
result.addAll(collection)
|
||||
return result
|
||||
if (collection is Collection) {
|
||||
val result = ArrayList<T>(this.size() + collection.size())
|
||||
result.addAll(this)
|
||||
result.addAll(collection)
|
||||
return result
|
||||
} else {
|
||||
val result = ArrayList<T>(this)
|
||||
result.addAll(collection)
|
||||
return result
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
// TODO: try to precalculate size
|
||||
// TODO: use immutable set builder when available
|
||||
doc(Sets) { "Returns a set containing all elements both of the original set and the given [collection]." }
|
||||
body(Sets) {
|
||||
@@ -91,20 +96,6 @@ fun generators(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("plus(collection: Collection<T>)") {
|
||||
only(Collections)
|
||||
doc { "Returns a list containing all elements of the original collection and then all elements of the given [collection]." }
|
||||
returns("List<T>")
|
||||
body {
|
||||
"""
|
||||
val result = ArrayList<T>(this.size() + collection.size())
|
||||
result.addAll(this)
|
||||
result.addAll(collection)
|
||||
return result
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("plus(array: Array<out T>)") {
|
||||
only(Iterables, Collections, Sets, Sequences)
|
||||
doc { "Returns a list containing all elements of the original collection and then all elements of the given [array]." }
|
||||
|
||||
Reference in New Issue
Block a user