anyTrue

fun anyTrue(vararg sources: LiveData<Boolean>): LiveData<Boolean>

Transforms sources to a LiveData which value is updated to true when any of the sources is true, updated to false otherwise.

Can be used as a short hand for:

combine(booleanSource1, booleanSource2) { values ->
value.any { it == true }
}.distinctUntilChanged()

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>(false)

// 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`

Parameters

sources

A list of Boolean LiveData instances.


fun Collection<LiveData<Boolean>>.anyTrue(): LiveData<Boolean>

Convenience method for calling anyTrue in a functional flow.