//Extensions for Jetpack Lifecycle/it.czerwinski.android.lifecycle.livedata/reduceNotNull

reduceNotNull

[androidJvm]
Content
fun <T> LiveData<T>.reduceNotNull(operation: (T, T) -> T): LiveData<T>
More info

Returns a LiveData emitting non-null accumulated value starting with the first non-null value emitted by this LiveData and applying operation from left to right to current accumulator value and each subsequent non-null value emitted by this LiveData.

operation will be executed on the main thread.

Example:

val newOperationsCountLiveData: LiveData = ... val operationsCountLiveData: LiveData = newOperationsCountLiveData.reduceNotNull { acc, next -> acc + next }