Se7eN
10/01/2020, 5:29 PMtemplatesDao.getAll().collectIndexed { index, templates ->
templatesLiveData.value = templates
if(index == 0) {
val newTemplates = getTemplatesFromFirestore(templates.lastIndex)
templatesDao.insert(newTemplates)
}
}
Is there any function like flow.onFirst { }
or something like thatansman
10/02/2020, 12:17 AMtravis
10/02/2020, 5:53 AMFlow
, then I tend to prefer avoiding side-effects in operators.
In other words, IMHO it would be nicer to have the LiveData
conversion separate from this operator.
For example:
private val all = templatesDao.getAll()
val allLiveData = all.asLiveData()
suspend fun example() {
val newTemplates = getTemplatesFromFirestore(all.first())
templatesDao.insert(newTemplates)
}
Se7eN
10/02/2020, 7:16 AM