Deprecate mapNotNull to change its behavior later.
#KT-4410
This commit is contained in:
@@ -6728,6 +6728,7 @@ public inline fun <R, C : MutableCollection<in R>> ShortArray.mapIndexedTo(desti
|
||||
/**
|
||||
* Returns a list containing the results of applying the given [transform] function to each non-null element of the original collection.
|
||||
*/
|
||||
@Deprecated("This function will change its semantics soon to map&filter rather than filter&map. Use filterNotNull().map {} instead.", ReplaceWith("filterNotNull().map(transform)"))
|
||||
public inline fun <T : Any, R> Array<out T?>.mapNotNull(transform: (T) -> R): List<R> {
|
||||
return mapNotNullTo(ArrayList<R>(), transform)
|
||||
}
|
||||
@@ -6736,6 +6737,7 @@ public inline fun <T : Any, R> Array<out T?>.mapNotNull(transform: (T) -> R): Li
|
||||
* Appends transformed non-null elements of original collection using the given [transform] function
|
||||
* to the given [destination].
|
||||
*/
|
||||
@Deprecated("This function will change its semantics soon to map&filter rather than filter&map. Use filterNotNull().mapTo(destination) {} instead.", ReplaceWith("filterNotNull().mapTo(destination, transform)"))
|
||||
public inline fun <T : Any, R, C : MutableCollection<in R>> Array<out T?>.mapNotNullTo(destination: C, transform: (T) -> R): C {
|
||||
for (element in this) {
|
||||
if (element != null) {
|
||||
|
||||
@@ -1080,6 +1080,7 @@ public inline fun <T, R, C : MutableCollection<in R>> Iterable<T>.mapIndexedTo(d
|
||||
/**
|
||||
* Returns a list containing the results of applying the given [transform] function to each non-null element of the original collection.
|
||||
*/
|
||||
@Deprecated("This function will change its semantics soon to map&filter rather than filter&map. Use filterNotNull().map {} instead.", ReplaceWith("filterNotNull().map(transform)"))
|
||||
public inline fun <T : Any, R> Iterable<T?>.mapNotNull(transform: (T) -> R): List<R> {
|
||||
return mapNotNullTo(ArrayList<R>(), transform)
|
||||
}
|
||||
@@ -1088,6 +1089,7 @@ public inline fun <T : Any, R> Iterable<T?>.mapNotNull(transform: (T) -> R): Lis
|
||||
* Appends transformed non-null elements of original collection using the given [transform] function
|
||||
* to the given [destination].
|
||||
*/
|
||||
@Deprecated("This function will change its semantics soon to map&filter rather than filter&map. Use filterNotNull().mapTo(destination) {} instead.", ReplaceWith("filterNotNull().mapTo(destination, transform)"))
|
||||
public inline fun <T : Any, R, C : MutableCollection<in R>> Iterable<T?>.mapNotNullTo(destination: C, transform: (T) -> R): C {
|
||||
for (element in this) {
|
||||
if (element != null) {
|
||||
|
||||
@@ -565,6 +565,7 @@ public inline fun <T, R, C : MutableCollection<in R>> Sequence<T>.mapIndexedTo(d
|
||||
/**
|
||||
* Returns a sequence containing the results of applying the given [transform] function to each non-null element of the original sequence.
|
||||
*/
|
||||
@Deprecated("This function will change its semantics soon to map&filter rather than filter&map. Use filterNotNull().map {} instead.", ReplaceWith("filterNotNull().map(transform)"))
|
||||
public fun <T : Any, R> Sequence<T?>.mapNotNull(transform: (T) -> R): Sequence<R> {
|
||||
return TransformingSequence(FilteringSequence(this, false, { it == null }) as Sequence<T>, transform)
|
||||
}
|
||||
@@ -573,6 +574,7 @@ public fun <T : Any, R> Sequence<T?>.mapNotNull(transform: (T) -> R): Sequence<R
|
||||
* Appends transformed non-null elements of original collection using the given [transform] function
|
||||
* to the given [destination].
|
||||
*/
|
||||
@Deprecated("This function will change its semantics soon to map&filter rather than filter&map. Use filterNotNull().mapTo(destination) {} instead.", ReplaceWith("filterNotNull().mapTo(destination, transform)"))
|
||||
public inline fun <T : Any, R, C : MutableCollection<in R>> Sequence<T?>.mapNotNullTo(destination: C, transform: (T) -> R): C {
|
||||
for (element in this) {
|
||||
if (element != null) {
|
||||
|
||||
@@ -65,9 +65,9 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
|
||||
open class SpecializedProperty<TKey: Any, TValue : Any>() {
|
||||
private val values = HashMap<TKey?, TValue>()
|
||||
|
||||
fun get(key: TKey): TValue? = values.getOrElse(key, { values.getOrElse(null, { null }) })
|
||||
operator fun get(key: TKey): TValue? = values.getOrElse(key, { values.getOrElse(null, { null }) })
|
||||
|
||||
fun set(keys: Collection<TKey>, value: TValue) {
|
||||
operator fun set(keys: Collection<TKey>, value: TValue) {
|
||||
if (keys.isEmpty())
|
||||
values[null] = value;
|
||||
else
|
||||
@@ -77,8 +77,8 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
|
||||
}
|
||||
}
|
||||
|
||||
fun invoke(vararg keys: TKey, valueBuilder: ()-> TValue) = set(keys.asList(), valueBuilder())
|
||||
fun invoke(value: TValue, vararg keys: TKey) = set(keys.asList(), value)
|
||||
operator fun invoke(vararg keys: TKey, valueBuilder: ()-> TValue) = set(keys.asList(), valueBuilder())
|
||||
operator fun invoke(value: TValue, vararg keys: TKey) = set(keys.asList(), value)
|
||||
|
||||
protected open fun onKeySet(key: TKey) {}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,8 @@ fun mapping(): List<GenericFunction> {
|
||||
inline(true)
|
||||
exclude(Strings, ArraysOfPrimitives)
|
||||
doc { "Returns a list containing the results of applying the given [transform] function to each non-null element of the original collection." }
|
||||
deprecate("This function will change its semantics soon to map&filter rather than filter&map. Use filterNotNull().map {} instead.")
|
||||
deprecateReplacement("filterNotNull().map(transform)")
|
||||
typeParam("T : Any")
|
||||
typeParam("R")
|
||||
returns("List<R>")
|
||||
@@ -172,6 +174,8 @@ fun mapping(): List<GenericFunction> {
|
||||
to the given [destination].
|
||||
"""
|
||||
}
|
||||
deprecate("This function will change its semantics soon to map&filter rather than filter&map. Use filterNotNull().mapTo(destination) {} instead.")
|
||||
deprecateReplacement("filterNotNull().mapTo(destination, transform)")
|
||||
typeParam("T : Any")
|
||||
typeParam("R")
|
||||
typeParam("C : MutableCollection<in R>")
|
||||
|
||||
Reference in New Issue
Block a user