https://kotlinlang.org logo
Title
m

menegatti

10/06/2017, 3:32 PM
sealed class Response
data class Success(val body : Data) : Response
data class Failure(val error : Throwable) : Response
...
if (res is Success) {
    updateUi(res.body)
}
t

trevjones

10/06/2017, 3:33 PM
this is how I like to do all my network calls where the logic that handles them is inside an
Observable.Transformer
l

lupajz

10/06/2017, 4:23 PM
fold that thing! 🙂
fun <T> Response.fold(failure: (Throwbable) -> T, success: (Data) -> T) = when(this) {
    is Success -> success(data)
    is Failure -> failure(error) 
}