-
-
Save cesarferreira/e5c0cbed166e0d5e0a68be0a6353cc8d to your computer and use it in GitHub Desktop.
Kotlin extension functions to convert LiveData to and from a Flowable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add the following to your build.gradle file | |
// implementation "android.arch.lifecycle:reactivestreams:1.0.0-beta1" | |
import android.arch.lifecycle.LifecycleOwner | |
import android.arch.lifecycle.LiveData | |
import android.arch.lifecycle.LiveDataReactiveStreams | |
import io.reactivex.Flowable | |
/** | |
* Converts LiveData into a Flowable | |
*/ | |
fun <T> LiveData<T>.toFlowable(lifecycleOwner: LifecycleOwner) : Flowable<T> = | |
Flowable.fromPublisher(LiveDataReactiveStreams.toPublisher(lifecycleOwner, this)) | |
/** | |
* Converts a Flowable into LiveData | |
*/ | |
fun <T> Flowable<T>.toLiveData(): LiveData<T> = LiveDataReactiveStreams.fromPublisher(this) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment