From 0851728454fdecebb596a13a2b6e3663088420f1 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Mon, 5 Oct 2015 21:05:42 +0300 Subject: [PATCH] Deprecate mapNotNull to change its behavior later. #KT-4410 --- libraries/stdlib/src/generated/_Arrays.kt | 2 ++ libraries/stdlib/src/generated/_Collections.kt | 2 ++ libraries/stdlib/src/generated/_Sequences.kt | 2 ++ libraries/tools/kotlin-stdlib-gen/src/templates/Engine.kt | 8 ++++---- .../tools/kotlin-stdlib-gen/src/templates/Mapping.kt | 4 ++++ 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libraries/stdlib/src/generated/_Arrays.kt b/libraries/stdlib/src/generated/_Arrays.kt index 4f2d04daef0..219ad3ab488 100644 --- a/libraries/stdlib/src/generated/_Arrays.kt +++ b/libraries/stdlib/src/generated/_Arrays.kt @@ -6728,6 +6728,7 @@ public inline fun > 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 Array.mapNotNull(transform: (T) -> R): List { return mapNotNullTo(ArrayList(), transform) } @@ -6736,6 +6737,7 @@ public inline fun Array.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 > Array.mapNotNullTo(destination: C, transform: (T) -> R): C { for (element in this) { if (element != null) { diff --git a/libraries/stdlib/src/generated/_Collections.kt b/libraries/stdlib/src/generated/_Collections.kt index 294dbe9e38c..c87c30779f6 100644 --- a/libraries/stdlib/src/generated/_Collections.kt +++ b/libraries/stdlib/src/generated/_Collections.kt @@ -1080,6 +1080,7 @@ public inline fun > Iterable.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 Iterable.mapNotNull(transform: (T) -> R): List { return mapNotNullTo(ArrayList(), transform) } @@ -1088,6 +1089,7 @@ public inline fun Iterable.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 > Iterable.mapNotNullTo(destination: C, transform: (T) -> R): C { for (element in this) { if (element != null) { diff --git a/libraries/stdlib/src/generated/_Sequences.kt b/libraries/stdlib/src/generated/_Sequences.kt index c5caf8ddcf1..ab7698c2582 100644 --- a/libraries/stdlib/src/generated/_Sequences.kt +++ b/libraries/stdlib/src/generated/_Sequences.kt @@ -565,6 +565,7 @@ public inline fun > Sequence.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 Sequence.mapNotNull(transform: (T) -> R): Sequence { return TransformingSequence(FilteringSequence(this, false, { it == null }) as Sequence, transform) } @@ -573,6 +574,7 @@ public fun Sequence.mapNotNull(transform: (T) -> R): Sequence> Sequence.mapNotNullTo(destination: C, transform: (T) -> R): C { for (element in this) { if (element != null) { diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Engine.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Engine.kt index f127b6d133b..2d757ae94de 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Engine.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Engine.kt @@ -65,9 +65,9 @@ class GenericFunction(val signature: String, val keyword: String = "fun") { open class SpecializedProperty() { private val values = HashMap() - 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, value: TValue) { + operator fun set(keys: Collection, 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) {} } diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Mapping.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Mapping.kt index d0213bb3762..05280b84ef1 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Mapping.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Mapping.kt @@ -96,6 +96,8 @@ fun mapping(): List { 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") @@ -172,6 +174,8 @@ fun mapping(): List { 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")