-
-
Save skydoves/3bb0dd7e4f5945b911248e4daa90a949 to your computer and use it in GitHub Desktop.
network_result_extensions
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
suspend fun <T : Any> NetworkResult<T>.onSuccess( | |
executable: suspend (T) -> Unit | |
): NetworkResult<T> = apply { | |
if (this is NetworkResult.Success<T>) { | |
executable(data) | |
} | |
} | |
suspend fun <T : Any> NetworkResult<T>.onError( | |
executable: suspend (code: Int, message: String?) -> Unit | |
): NetworkResult<T> = apply { | |
if (this is NetworkResult.Error<T>) { | |
executable(code, message) | |
} | |
} | |
suspend fun <T : Any> NetworkResult<T>.onException( | |
executable: suspend (e: Throwable) -> Unit | |
): NetworkResult<T> = apply { | |
if (this is NetworkResult.Exception<T>) { | |
executable(e) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment