Created
December 14, 2018 18:55
-
-
Save afollestad/4303908a32ac2884e6efc6ddd87b83ce to your computer and use it in GitHub Desktop.
Map and switchMap live data with extension functions instead of method calls.
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
import androidx.lifecycle.LiveData | |
import androidx.lifecycle.Transformations | |
fun <X, Y> LiveData<X>.map(mapper: (X) -> Y) = | |
Transformations.map(this, mapper)!! | |
fun <X, Y> LiveData<X>.switchMap(mapper: (X) -> LiveData<Y>) = | |
Transformations.switchMap(this, mapper)!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment