Media : branch upload to preview screen (need improvement)

This commit is contained in:
ganfra 2023-05-17 08:44:35 +02:00
parent c8ead4ab9f
commit f51d6a3cfd
15 changed files with 237 additions and 92 deletions

View file

@ -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)
}
}