Skip to content

Commit

Permalink
chore(base/Result): add onResult to easen up usage of early error pro…
Browse files Browse the repository at this point in the history
…pagation
  • Loading branch information
benjohnde committed Aug 26, 2020
1 parent c566048 commit b275233
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions auth/src/commonMain/kotlin/com/liftric/base/Result.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class Result<out T> constructor(val value: Any?) {
}
}

inline fun <T, R> Result<T>.onResult(action: (value: T) -> Result<R>): Result<R> {
return when (value) {
is Result.Failure -> Result.failure(value.exception)
else -> action(value as T)
}
}

fun Result<*>.throwOnFailure() {
if (value is Result.Failure) throw value.exception
}
Expand Down

0 comments on commit b275233

Please sign in to comment.