From eecd1b7d9946f541af3f5d453905024ff97e7c26 Mon Sep 17 00:00:00 2001 From: Michael Bull Date: Tue, 5 Mar 2024 15:16:31 +0000 Subject: [PATCH] Remove deprecated functions --- .../coroutines/binding/SuspendableBinding.kt | 22 --------- .../com/github/michaelbull/result/And.kt | 9 ---- .../com/github/michaelbull/result/Binding.kt | 6 --- .../com/github/michaelbull/result/Get.kt | 18 -------- .../com/github/michaelbull/result/Iterable.kt | 45 ------------------- .../com/github/michaelbull/result/Or.kt | 9 ---- .../com/github/michaelbull/result/Result.kt | 16 ------- .../com/github/michaelbull/result/Unwrap.kt | 18 -------- .../result/coroutines/SuspendableBinding.kt | 32 ------------- 9 files changed, 175 deletions(-) delete mode 100644 kotlin-result-coroutines/src/commonMain/kotlin/com/github/michaelbull/result/coroutines/binding/SuspendableBinding.kt delete mode 100644 kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/coroutines/SuspendableBinding.kt diff --git a/kotlin-result-coroutines/src/commonMain/kotlin/com/github/michaelbull/result/coroutines/binding/SuspendableBinding.kt b/kotlin-result-coroutines/src/commonMain/kotlin/com/github/michaelbull/result/coroutines/binding/SuspendableBinding.kt deleted file mode 100644 index ed61b42..0000000 --- a/kotlin-result-coroutines/src/commonMain/kotlin/com/github/michaelbull/result/coroutines/binding/SuspendableBinding.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.michaelbull.result.coroutines.binding - -import com.github.michaelbull.result.Result -import com.github.michaelbull.result.coroutines.CoroutineBindingScope -import com.github.michaelbull.result.coroutines.coroutineBinding - -@Deprecated( - message = "Use coroutineBinding instead", - replaceWith = ReplaceWith( - expression = "coroutineBinding(block)", - imports = ["com.github.michaelbull.result.coroutines.coroutineBinding"] - ) -) -public suspend inline fun binding(crossinline block: suspend CoroutineBindingScope.() -> V): Result { - return coroutineBinding(block) -} - -@Deprecated( - message = "Use CoroutineBindingScope instead", - replaceWith = ReplaceWith("CoroutineBindingScope") -) -public typealias SuspendableResultBinding = CoroutineBindingScope diff --git a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/And.kt b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/And.kt index 1acfb30..b1fb391 100644 --- a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/And.kt +++ b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/And.kt @@ -15,15 +15,6 @@ public infix fun Result.and(result: Result): Result } } -@Deprecated("Use andThen instead", ReplaceWith("andThen { result() }")) -public inline infix fun Result.and(result: () -> Result): Result { - contract { - callsInPlace(result, InvocationKind.AT_MOST_ONCE) - } - - return andThen { result() } -} - /** * Maps this [Result][Result] to [Result][Result] by either applying the [transform] * function if this result [is ok][Result.isOk], or returning [this]. diff --git a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Binding.kt b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Binding.kt index 5202043..b2e4533 100644 --- a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Binding.kt +++ b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Binding.kt @@ -41,12 +41,6 @@ public inline fun binding(crossinline block: BindingScope.() -> V): Re internal expect object BindException : Exception -@Deprecated( - message = "Use BindingScope instead", - replaceWith = ReplaceWith("BindingScope") -) -public typealias ResultBinding = BindingScope - public interface BindingScope { public fun Result.bind(): V } diff --git a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Get.kt b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Get.kt index f9a395b..815b8e6 100644 --- a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Get.kt +++ b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Get.kt @@ -55,15 +55,6 @@ public infix fun Result.getOr(default: V): V { } } -@Deprecated("Use getOrElse instead", ReplaceWith("getOrElse { default() }")) -public inline infix fun Result.getOr(default: () -> V): V { - contract { - callsInPlace(default, InvocationKind.AT_MOST_ONCE) - } - - return getOrElse { default() } -} - /** * Returns the [error][Result.error] if this result [is an error][Result.isErr], otherwise * [default]. @@ -80,15 +71,6 @@ public infix fun Result.getErrorOr(default: E): E { } } -@Deprecated("Use getOrElse instead", ReplaceWith("getErrorOrElse { default() }")) -public inline infix fun Result.getErrorOr(default: () -> E): E { - contract { - callsInPlace(default, InvocationKind.AT_MOST_ONCE) - } - - return getErrorOrElse { default() } -} - /** * Returns the [value][Result.value] if this result [is ok][Result.isOk], otherwise the * [transformation][transform] of the [error][Result.error]. diff --git a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Iterable.kt b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Iterable.kt index bd0b95b..c1c86a0 100644 --- a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Iterable.kt +++ b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Iterable.kt @@ -170,29 +170,6 @@ public fun > valuesOf(vararg results: R): List { return results.asIterable().filterValues() } -@Deprecated( - message = "Use allValuesOf instead", - replaceWith = ReplaceWith("valuesOf(results)") -) -public fun > getAll(vararg results: R): List { - return results.asIterable().filterValues() -} - - -/** - * Extracts from an [Iterable] of [Results][Result] all the [Ok] elements. All the [Ok] elements - * are extracted in order. - * - * - Haskell: [Data.Either.lefts](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:lefts) - */ -@Deprecated( - message = "Use filterValues instead", - replaceWith = ReplaceWith("filterValues()") -) -public fun Iterable>.getAll(): List { - return filterValues() -} - /** * Returns a [List] containing the [error][Result.error] of each element in the specified [results] * that [is an error][Result.isErr]. Elements in the returned list are in the same order as the @@ -204,28 +181,6 @@ public fun > errorsOf(vararg results: R): List { return results.asIterable().filterErrors() } -@Deprecated( - message = "Use errorsOf instead", - replaceWith = ReplaceWith("errorsOf(results)") -) -public fun > getAllErrors(vararg results: R): List { - return results.asIterable().filterErrors() -} - -/** - * Extracts from an [Iterable] of [Results][Result] all the [Err] elements. All the [Err] elements - * are extracted in order. - * - * - Haskell: [Data.Either.rights](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:rights) - */ -@Deprecated( - message = "Use filterErrors instead", - replaceWith = ReplaceWith("filterErrors()") -) -public fun Iterable>.getAllErrors(): List { - return filterErrors() -} - /** * Partitions the specified [results] into a [Pair] of [Lists][List]. An element that * [is ok][Result.isOk] will appear in the [first][Pair.first] list, whereas an element that diff --git a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Or.kt b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Or.kt index c0f20b9..2b993fd 100644 --- a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Or.kt +++ b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Or.kt @@ -15,15 +15,6 @@ public infix fun Result.or(result: Result): Result { } } -@Deprecated("Use orElse instead", ReplaceWith("orElse { result() }")) -public inline infix fun Result.or(result: () -> Result): Result { - contract { - callsInPlace(result, InvocationKind.AT_MOST_ONCE) - } - - return orElse { result() } -} - /** * Returns the [transformation][transform] of the [error][Result.error] if this result * [is an error][Result.isErr], otherwise [this]. diff --git a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Result.kt b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Result.kt index 3eb5c53..9cb3cfa 100644 --- a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Result.kt +++ b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Result.kt @@ -51,22 +51,6 @@ public sealed class Result { public abstract operator fun component1(): V? public abstract operator fun component2(): E? - - public companion object { - - /** - * Invokes a [function] and wraps it in a [Result], returning an [Err] - * if an [Exception] was thrown, otherwise [Ok]. - */ - @Deprecated("Use top-level runCatching instead", ReplaceWith("runCatching(function)")) - public inline fun of(function: () -> V): Result { - return try { - Ok(function.invoke()) - } catch (ex: Exception) { - Err(ex) - } - } - } } /** diff --git a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Unwrap.kt b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Unwrap.kt index 9c5d42e..136b65f 100644 --- a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Unwrap.kt +++ b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Unwrap.kt @@ -24,15 +24,6 @@ public fun Result.unwrap(): V { } } -@Deprecated("Use lazy-evaluating variant instead", ReplaceWith("expect { message }")) -public infix fun Result.expect(message: String): V { - contract { - returns() implies (this@expect is Ok) - } - - return expect { message } -} - /** * Returns the [value][Result.value] if this result [is ok][Result.isOk], otherwise throws an * [UnwrapException] with the specified [message]. @@ -75,15 +66,6 @@ public fun Result.unwrapError(): E { } } -@Deprecated("Use lazy-evaluating variant instead", ReplaceWith("expectError { message }")) -public infix fun Result.expectError(message: String): E { - contract { - returns() implies (this@expectError is Err) - } - - return expectError { message } -} - /** * Returns the [error][Result.error] if this result [is an error][Result.isErr], otherwise throws * an [UnwrapException] with the specified [message]. diff --git a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/coroutines/SuspendableBinding.kt b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/coroutines/SuspendableBinding.kt deleted file mode 100644 index 93a9c02..0000000 --- a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/coroutines/SuspendableBinding.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.github.michaelbull.result.coroutines - -import com.github.michaelbull.result.BindException -import com.github.michaelbull.result.BindingScope -import com.github.michaelbull.result.BindingScopeImpl -import com.github.michaelbull.result.Ok -import com.github.michaelbull.result.Result -import kotlin.contracts.InvocationKind -import kotlin.contracts.contract - -/** - * Suspending variant of [binding][com.github.michaelbull.result.binding]. - */ -@Deprecated( - message = "Will throw a runtime exception if used with async requests that fail to bind. " + - "See https://github.com/michaelbull/kotlin-result/pull/28 " + - "Please import the kotlin-result-coroutines library to continue using this feature.", - level = DeprecationLevel.WARNING -) -public suspend inline fun binding(crossinline block: suspend BindingScope.() -> V): Result { - contract { - callsInPlace(block, InvocationKind.EXACTLY_ONCE) - } - - return with(BindingScopeImpl()) { - try { - Ok(block()) - } catch (ex: BindException) { - result!! - } - } -}