mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Python Result: create aliases to simplify migration from kotlin Result
GitOrigin-RevId: 64b9ad7f1d458253c7d43bef74bef9f8fd88f697
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a8afc1e335
commit
e271220bac
@@ -87,14 +87,21 @@ sealed class Result<out SUCC, out ERR> {
|
||||
/**
|
||||
* Like Rust `unwrap`: returns result or throws exception. Use when error is unexpected
|
||||
*/
|
||||
fun orThrow(onError: (ERR) -> Throwable = { e -> if (e is Throwable) e else AssertionError(e) }): SUCC {
|
||||
fun orThrow(onError: (ERR) -> Throwable = { e -> if (e is Throwable) e else AssertionError(e) }): SUCC {
|
||||
when (this) {
|
||||
is Success -> return result
|
||||
is Failure -> throw onError(this.error)
|
||||
}
|
||||
}
|
||||
|
||||
// To be backward compatible with Kotlin result
|
||||
companion object {
|
||||
fun <S> success(value: S) = Success(value)
|
||||
fun <E> failure(error: E) = Failure(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Maps success result to another one with same error
|
||||
* ```kotlin
|
||||
|
||||
Reference in New Issue
Block a user