Last active
January 31, 2020 04:52
-
-
Save kichiemon/6238e6df9ba061a52cb3074cf443be58 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
fun <A, B> LiveData<A>.combineLatestWith(other: LiveData<B>): LiveData<Pair<A, B>> { | |
val mediator = MediatorLiveData<Pair<A, B>>() | |
mediator.addSource(this) { | |
it?.let { thisValue -> | |
other.value?.let { otherValue -> | |
mediator.value = Pair(thisValue, otherValue) | |
} | |
} | |
} | |
mediator.addSource(other) { | |
it?.let { otherValue -> | |
this.value?.let { thisValue -> | |
mediator.value = Pair(thisValue, otherValue) | |
} | |
} | |
} | |
return mediator | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment