Is there, in kotlin and android, something similar to switchmap in rxjs or rxjava?

Viewed 352

I want to find out is there something similar to switchmap in kotlin and android (LiveData maybe).

I need to change my request immediately after events that can happen very often and which determine what to request from the server, respectively, I only need the last request

1 Answers

In Kotlin you can use the Transformations library as follows

val someLiveData: LiveData<Type> = ...

val someOtherValue = Transformations.switchMap(someLiveData) { changedValue: Type ->
    //Assign someOtherValue using changedValue, the value coming from someLiveData.
}
Related