Created
August 11, 2022 17:18
-
-
Save Jeff-Soares/fb87992935f25044169167648d5c17ac to your computer and use it in GitHub Desktop.
combine operator for livedata
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
fun <T, K, R> LiveData<T>.combineWith( | |
liveData: LiveData<K>, | |
block: (T?, K?) -> R | |
): LiveData<R> { | |
val result = MediatorLiveData<R>() | |
result.addSource(this) { | |
result.value = block(this.value, liveData.value) | |
} | |
result.addSource(liveData) { | |
result.value = block(this.value, liveData.value) | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment