Merge pull request #175 from TouchInstinct/add_content_event_transform

Add transform method into ContentEvent
This commit is contained in:
crainzavr 2020-10-07 17:12:20 +05:00 committed by GitHub
commit 060aa5bb6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -10,4 +10,13 @@ sealed class ContentEvent<out T>(open val data: T?) {
data class Complete<out T>(override val data: T? = null) : ContentEvent<T>(data)
fun <P> transform(transformation: (T?) -> P): ContentEvent<P> {
return when(this) {
is Loading -> Loading(transformation(data))
is Success -> Success(transformation(data))
is Complete -> Complete(transformation(data))
is Error -> Error(throwable, transformation(data))
}
}
}