在 kotlin 和 android 中,是否有类似于 rxjs 或 rxjava 中的 switchmap 的东西?

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

我想知道 kotlin 和 android(也许是 LiveData)中是否有类似于 switchmap 的东西。

我需要在经常发生的事件之后立即更改我的请求,这些事件分别决定了从服务器请求什么,我只需要最后一个请求

在 Kotlin 中,您可以按如下方式使用转换库

val someLiveData: LiveData<Type> = ...

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