Skip to content

Commit

Permalink
bring back some deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nek-12 committed Aug 26, 2023
1 parent 41ab6b4 commit 7fe114c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion core/src/commonMain/kotlin/pro/respawn/apiresult/ApiResult.kt
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,19 @@ public inline fun <T> ApiResult<T>.errorUnless(
predicate: (T) -> Boolean,
): ApiResult<T> = errorIf(exception) { !predicate(it) }

/**
* Makes [this] an [Error] if [predicate] returns false
* @see errorIf
*/
@Deprecated(
"renamed to errorUnless",
ReplaceWith("this.errorUnless(exception, predicate)", "pro.respawn.apiresult.errorUnless")
)
public inline fun <T> ApiResult<T>.errorIfNot(
exception: () -> Exception = { ConditionNotSatisfiedException() },
predicate: (T) -> Boolean,
): ApiResult<T> = errorUnless(exception, predicate)

/**
* Makes [this] an [Error] if [predicate] returns true
* @see errorUnless
Expand Down Expand Up @@ -543,5 +556,5 @@ public inline fun <T> ApiResult<T>.require(
): ApiResult<T> =
errorUnless(
exception = { IllegalArgumentException(message()) },
predicate = predicate,
predicate = predicate
)
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ public inline fun <T> Sequence<ApiResult<T>>.filterSuccesses(): Sequence<Success
/**
* Filters all null values of [Success]es
*/
public inline fun <T> Iterable<ApiResult<T?>>.filterNotNull(): List<ApiResult<T & Any>> =
public inline fun <T> Iterable<ApiResult<T?>>.filterNulls(): List<ApiResult<T & Any>> =
filter { it !is Success || it.result != null }.mapResults { it!! }

/**
* Filters all null values of [Success]es
*/
public inline fun <T> Sequence<ApiResult<T?>>.filterNotNull(): Sequence<ApiResult<T & Any>> =
public inline fun <T> Sequence<ApiResult<T?>>.filterNulls(): Sequence<ApiResult<T & Any>> =
filter { it !is Success || it.result != null }.mapResults { it!! }

/**
Expand Down

0 comments on commit 7fe114c

Please sign in to comment.