ifTrue
Executes and switchMaps to block if this has a true value. If this is false or null, it returns LiveData with value null. If this should not return null, ifTrueOrDefault can be used instead.
This can be used to replace:
myLiveData.switchMap {
if (it == true) {
myNewLiveData
} else {
EmptyLiveData()
}
}.distinctUntilChanged()Content copied to clipboard
with a more concise syntax:
myLiveData.ifTrue { myNewLiveData }Content copied to clipboard