Skip to content

Commit

Permalink
Remove deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbull committed Mar 11, 2024
1 parent b19894a commit 0605c1a
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 159 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ public infix fun <V, E, U> Result<V, E>.and(result: Result<U, E>): Result<U, E>
}
}

@Deprecated("Use andThen instead", ReplaceWith("andThen { result() }"))
public inline infix fun <V, E, U> Result<V, E>.and(result: () -> Result<U, E>): Result<U, E> {
contract {
callsInPlace(result, InvocationKind.AT_MOST_ONCE)
}

return andThen { result() }
}

/**
* Maps this [Result<V, E>][Result] to [Result<U, E>][Result] by either applying the [transform]
* function if this [Result] is [Ok], or returning this [Err].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ public inline fun <V, E> binding(crossinline block: BindingScope<E>.() -> V): Re

internal expect object BindException : Exception

@Deprecated(
message = "Use BindingScope instead",
replaceWith = ReplaceWith("BindingScope<E>")
)
public typealias ResultBinding<E> = BindingScope<E>

public interface BindingScope<E> {
public fun <V> Result<V, E>.bind(): V
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@ public infix fun <V, E> Result<V, E>.getOr(default: V): V {
}
}

@Deprecated("Use getOrElse instead", ReplaceWith("getOrElse { default() }"))
public inline infix fun <V, E> Result<V, E>.getOr(default: () -> V): V {
contract {
callsInPlace(default, InvocationKind.AT_MOST_ONCE)
}

return getOrElse { default() }
}

/**
* Returns the [error][Err.error] if this [Result] is [Err], otherwise [default].
*
Expand All @@ -79,15 +70,6 @@ public infix fun <V, E> Result<V, E>.getErrorOr(default: E): E {
}
}

@Deprecated("Use getOrElse instead", ReplaceWith("getErrorOrElse { default() }"))
public inline infix fun <V, E> Result<V, E>.getErrorOr(default: () -> E): E {
contract {
callsInPlace(default, InvocationKind.AT_MOST_ONCE)
}

return getErrorOrElse { default() }
}

/**
* Returns the [value][Ok.value] if this [Result] is [Ok], otherwise the
* [transformation][transform] of the [error][Err.error].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,6 @@ public fun <V, E, R : Result<V, E>> getAll(vararg results: R): List<V> {
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 <V, E> Iterable<Result<V, E>>.getAll(): List<V> {
return filterValues()
}

/**
* Extracts from a vararg of [Results][Result] all the [Err] elements. All the [Err] elements are
* extracted in order.
Expand All @@ -187,20 +173,6 @@ public fun <V, E, R : Result<V, E>> getAllErrors(vararg results: R): List<E> {
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 <V, E> Iterable<Result<V, E>>.getAllErrors(): List<E> {
return filterErrors()
}

/**
* Partitions a vararg of [Results][Result] into a [Pair] of [Lists][List]. All the [Ok] elements
* are extracted, in order, to the [first][Pair.first] value. Similarly the [Err] elements are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ public infix fun <V, E, F> Result<V, E>.or(result: Result<V, F>): Result<V, F> {
}
}

@Deprecated("Use orElse instead", ReplaceWith("orElse { result() }"))
public inline infix fun <V, E, F> Result<V, E>.or(result: () -> Result<V, F>): Result<V, F> {
contract {
callsInPlace(result, InvocationKind.AT_MOST_ONCE)
}

return orElse { result() }
}

/**
* Returns the [transformation][transform] of the [error][Err.error] if this [Result] is [Err],
* otherwise this [Ok].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,8 @@ package com.github.michaelbull.result
* - Rust: [Result](https://doc.rust-lang.org/std/result/enum.Result.html)
*/
public sealed class Result<out V, out E> {

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 <V> of(function: () -> V): Result<V, Exception> {
return try {
Ok(function.invoke())
} catch (ex: Exception) {
Err(ex)
}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ public fun <V, E> Result<V, E>.unwrap(): V {
}
}

@Deprecated("Use lazy-evaluating variant instead", ReplaceWith("expect { message }"))
public infix fun <V, E> Result<V, E>.expect(message: String): V {
contract {
returns() implies (this@expect is Ok<V>)
}

return expect { message }
}

/**
* Unwraps a [Result], yielding the [value][Ok.value].
*
Expand Down Expand Up @@ -70,15 +61,6 @@ public fun <V, E> Result<V, E>.unwrapError(): E {
}
}

@Deprecated("Use lazy-evaluating variant instead", ReplaceWith("expectError { message }"))
public infix fun <V, E> Result<V, E>.expectError(message: String): E {
contract {
returns() implies (this@expectError is Err<E>)
}

return expectError { message }
}

/**
* Unwraps a [Result], yielding the [error][Err.error].
*
Expand Down

This file was deleted.

0 comments on commit 0605c1a

Please sign in to comment.