Created
April 3, 2023 06:35
-
-
Save ShivamKumarJha/9a992eb7c476e2cc065a5423559f330b to your computer and use it in GitHub Desktop.
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.MediatorLiveData | |
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