Introduce plusElement and minusElement to disambiguate situations like List<List<T>> + List<T>

#KT-9992 Fixed
This commit is contained in:
Ilya Gorbunov
2016-01-26 18:42:30 +03:00
parent fb21ef2e1d
commit 8d02467e6d
10 changed files with 134 additions and 0 deletions
@@ -12358,6 +12358,14 @@ public operator fun ShortArray.plus(elements: ShortArray): ShortArray {
return result
}
/**
* Returns an array containing all elements of the original array and then the given [element].
*/
@kotlin.jvm.JvmVersion
public fun <T> Array<T>.plusElement(element: T): Array<T> {
return plus(element)
}
/**
* Sorts the array in-place.
*/
@@ -1599,6 +1599,13 @@ public operator fun <T> Iterable<T>.minus(elements: Sequence<T>): List<T> {
return this.filterNot { it in other }
}
/**
* Returns a list containing all elements of the original collection without the first occurrence of the given [element].
*/
public fun <T> Iterable<T>.minusElement(element: T): List<T> {
return minus(element)
}
/**
* Splits the original collection into pair of lists,
* where *first* list contains elements for which [predicate] yielded `true`,
@@ -1706,6 +1713,20 @@ public operator fun <T> Iterable<T>.plus(elements: Sequence<T>): List<T> {
return result
}
/**
* Returns a list containing all elements of the original collection and then the given [element].
*/
public fun <T> Collection<T>.plusElement(element: T): List<T> {
return plus(element)
}
/**
* Returns a list containing all elements of the original collection and then the given [element].
*/
public fun <T> Iterable<T>.plusElement(element: T): List<T> {
return plus(element)
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
@@ -1024,6 +1024,13 @@ public operator fun <T> Sequence<T>.minus(elements: Sequence<T>): Sequence<T> {
}
}
/**
* Returns a sequence containing all elements of the original sequence without the first occurrence of the given [element].
*/
public fun <T> Sequence<T>.minusElement(element: T): Sequence<T> {
return minus(element)
}
/**
* Splits the original sequence into pair of lists,
* where *first* list contains elements for which [predicate] yielded `true`,
@@ -1076,6 +1083,13 @@ public operator fun <T> Sequence<T>.plus(elements: Sequence<T>): Sequence<T> {
return sequenceOf(this, elements).flatten()
}
/**
* Returns a sequence containing all elements of the original sequence and then the given [element].
*/
public fun <T> Sequence<T>.plusElement(element: T): Sequence<T> {
return plus(element)
}
/**
* Returns a sequence of pairs built from elements of both sequences with same indexes.
* Resulting sequence has length of shortest input sequence.
+14
View File
@@ -54,6 +54,13 @@ public operator fun <T> Set<T>.minus(elements: Sequence<T>): Set<T> {
return result
}
/**
* Returns a set containing all elements of the original set except the given [element].
*/
public fun <T> Set<T>.minusElement(element: T): Set<T> {
return minus(element)
}
/**
* Returns a set containing all elements of the original set and then the given [element].
*/
@@ -94,3 +101,10 @@ public operator fun <T> Set<T>.plus(elements: Sequence<T>): Set<T> {
return result
}
/**
* Returns a set containing all elements of the original set and then the given [element].
*/
public fun <T> Set<T>.plusElement(element: T): Set<T> {
return plus(element)
}