Last active
August 13, 2019 12:18
-
-
Save LukaKordic/555c9187aa1adcf62a4c7417eb73b117 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class Result<out T : Any> | |
data class Success<out T : Any>(val data: T) : Result<T>() | |
data class Failure(val httpError: HttpError) : Result<Nothing>() | |
class HttpError(val throwable: Throwable, val errorCode: Int = 0) | |
inline fun <T : Any> Result<T>.onSuccess(action: (T) -> Unit): Result<T> { | |
if (this is Success) action(data) | |
return this | |
} | |
inline fun <T : Any> Result<T>.onFailure(action: (HttpError) -> Unit) { | |
if (this is Failure) action(httpError) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment