-
-
Save aoudiamoncef/ef7804abdba930a4c358e40cf47af7d6 to your computer and use it in GitHub Desktop.
Kotlin extension functions to convert LiveData to and from a Flowable
This file contains hidden or 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