allTrue
Transforms sources to a LiveData which value is updated to true
when all sources are true
, updated to false
otherwise.
Can be used as a short hand for:
combine(booleanSource1, booleanSource2) { values ->
value.all { it == true }
}.distinctUntilChanged()
Content copied to clipboard
As with combine, the returned LiveData does not have a value as long as it is not observed. Like for other MediatorLiveData instances the value returned by LiveData.getValue is not updated when the LiveData instances has no observer.
Observers are only invoked when the value changes.
For example:
// GIVEN
val source1 = MutableLiveData<Int?>(1)
val source2 = MutableLiveData<Boolean>(true)
// WHEN
val combined = allTrue(
source1.map { it == 1 },
source2
)
// THEN
// Observing combined.value yields `true`
// WHEN
source1.value = null
// THEN
// Observing combined.value yields `false`
Content copied to clipboard
Parameters
sources
A list of Boolean LiveData instances.
Convenience method for calling allTrue in a functional flow.