Skip to content

Instantly share code, notes, and snippets.

@psteiger
Created June 29, 2019 21:05
Show Gist options
  • Select an option

  • Save psteiger/4d3c61b3250b074162263e627d4e9be4 to your computer and use it in GitHub Desktop.

Select an option

Save psteiger/4d3c61b3250b074162263e627d4e9be4 to your computer and use it in GitHub Desktop.
fun <T> Resource<T>.onSuccess(
onSuccess: (data: T) -> Unit
): Resource<T> {
if (this is Resource.Success<T>)
onSuccess(data)
return this
}
fun <T> Resource<T>.onLoading(
onLoading: (partialData: T?) -> Unit
): Resource<T> {
if (this is Resource.Loading)
onLoading(partialData)
return this
}
fun <T> Resource<T>.onFailure(
onFailure: (throwable: Throwable?) -> Unit
): Resource<T> {
if (this is Resource.Failure)
onFailure(throwable)
return this
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment