mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 12:07:28 +00:00
Media : branch upload to preview screen (need improvement)
This commit is contained in:
@@ -25,3 +25,16 @@ inline fun <R, T : R> Result<T>.mapFailure(transform: (exception: Throwable) ->
|
||||
else -> Result.failure(transform(exception))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to transform some Throwable into some other.
|
||||
*/
|
||||
inline fun <R, T> Result<R>.flatMap(transform: (R) -> Result<T>): Result<T> {
|
||||
return when (val exception = exceptionOrNull()) {
|
||||
null -> mapCatching(transform).fold(
|
||||
onSuccess = { it },
|
||||
onFailure = { Result.failure(it) }
|
||||
)
|
||||
else -> Result.failure(exception)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user