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
@@ -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.
*/