diff --git a/README.md b/README.md index 028e6f8..2728257 100644 --- a/README.md +++ b/README.md @@ -597,7 +597,6 @@ For example, it allows replacing the following snippet: ```kotlin someComponent.getSomeNullableValue() .let { it ?: someComponent.getFallbackValue() } - .let { it as? Boolean } ?.let { if (it) doSomething() else null @@ -609,7 +608,6 @@ with: ```kotlin someComponent.getSomeNullableValue() .ifNull { someComponent.getFallbackValue() } - .safeCast() .ifTrue { doSomething() } ``` @@ -661,6 +659,10 @@ Contributors: Timon Kanters, Jeroen Erik Jensen, Krzysztof Karczewski ## Release notes +### 1.6.2 + +* Removed cast extensions. + ### 1.6.1 * Enables explicit API, requiring stricter type and visibility definitions of our public APIs. diff --git a/extensions/pom.xml b/extensions/pom.xml index 09b076e..beff631 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -24,7 +24,7 @@ com.tomtom.kotlin kotlin-tools - 1.6.1 + 1.6.2 extensions diff --git a/extensions/src/main/java/com/tomtom/kotlin/extensions/CastExtensions.kt b/extensions/src/main/java/com/tomtom/kotlin/extensions/CastExtensions.kt deleted file mode 100644 index 2ea8267..0000000 --- a/extensions/src/main/java/com/tomtom/kotlin/extensions/CastExtensions.kt +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2012-2022, TomTom (http://tomtom.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.tomtom.kotlin.extensions - -/** - * Casts `this` to `T`, throwing a [ClassCastException] if the cast fails. - * - * This can be used to replace: - * - * ```kotlin - * ( - * myObject - * .chainCall() - * .chainCall() - * as MyClass - * ).chainCall() - * ``` - * - * or: - * - * ```kotlin - * myObject - * .chainCall() - * .chainCall() - * .let { it as MyClass } - * .chainCall() - * ``` - * - * with a more functional-programming-friendly syntax: - * - * ```kotlin - * myObject - * .chainCall() - * .chainCall() - * .cast() - * .chainCall() - * ``` - * - * This method is not intended to replace all casts; the `as` operator is fine in many cases. In - * chain-calling constructs however, the `as` operator can easily lead to reduced readability. `let` - * helps with this, but adds boilerplate that distracts from the functional flow. - */ -public inline fun Any.cast(): T = - this as T - -/** - * Casts `this` to `T`, returning `null` if the cast fails. - * - * This can be used to replace: - * - * ```kotlin - * ( - * myObject - * .chainCall() - * .chainCall() - * as? MyClass - * )?.chainCall() - * ``` - * - * or: - * - * ```kotlin - * myObject - * .chainCall() - * .chainCall() - * .let { it as? MyClass } - * ?.chainCall() - * ``` - * - * with a more functional-programming-friendly syntax: - * - * ```kotlin - * myObject - * .chainCall() - * .chainCall() - * .safeCast() - * ?.chainCall() - * ``` - * - * This method is not intended to replace all casts; the `as?` operator is fine in many cases. In - * chain-calling constructs however, the `as?` operator can easily lead to reduced readability. - * `let` helps with this, but adds boilerplate that distracts from the functional flow. - */ -public inline fun Any.safeCast(): T? = - this as? T diff --git a/extensions/src/test/java/com/tomtom/kotlin/extensions/CastExtensionsTest.kt b/extensions/src/test/java/com/tomtom/kotlin/extensions/CastExtensionsTest.kt deleted file mode 100644 index 11ede74..0000000 --- a/extensions/src/test/java/com/tomtom/kotlin/extensions/CastExtensionsTest.kt +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2012-2022, TomTom (http://tomtom.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.tomtom.kotlin.extensions - -import kotlin.test.assertEquals -import kotlin.test.assertFailsWith -import kotlin.test.assertNull -import org.junit.Test - -internal class CastExtensionsTest { - - @Test - fun `successful cast`() { - // GIVEN - val sut: Number = 1 - - // WHEN - val result: Int = sut.cast() - - // THEN - assertEquals(1, result) - } - - @Test - fun `unsuccessful cast`() { - // GIVEN - val sut: Number = 1 - - // WHEN-THEN - assertFailsWith { - sut.cast() - } - } - - @Test - fun `successful safeCast`() { - // GIVEN - val sut: Number = 1 - - // WHEN - val result: Int? = sut.safeCast() - - // THEN - assertEquals(1, result) - } - - @Test - fun `unsuccessful safeCast`() { - // GIVEN - val sut: Number = 1 - - // WHEN - val result: Long? = sut.safeCast() - - // THEN - assertNull(result) - } -} diff --git a/memoization/pom.xml b/memoization/pom.xml index 606c833..294bac2 100644 --- a/memoization/pom.xml +++ b/memoization/pom.xml @@ -24,7 +24,7 @@ com.tomtom.kotlin kotlin-tools - 1.6.1 + 1.6.2 memoization diff --git a/pom.xml b/pom.xml index 24b2a74..d1aaca1 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ com.tomtom.kotlin kotlin-tools - 1.6.1 + 1.6.2 pom Kotlin Tools diff --git a/traceevents/pom.xml b/traceevents/pom.xml index f7e3eb3..0215a12 100644 --- a/traceevents/pom.xml +++ b/traceevents/pom.xml @@ -24,7 +24,7 @@ com.tomtom.kotlin kotlin-tools - 1.6.1 + 1.6.2 traceevents diff --git a/uid/pom.xml b/uid/pom.xml index 2c638c4..6bc9a1e 100644 --- a/uid/pom.xml +++ b/uid/pom.xml @@ -24,7 +24,7 @@ com.tomtom.kotlin kotlin-tools - 1.6.1 + 1.6.2 uid