I have a scenario to modify each Object
of the Single<List<Object>>
refer to this. What I want to ask is how to set properties to each item with other Single/Observable result. I'm not sure with my method setProps()
is correct. I got error when the result of the propsA/propsB is empty/null, and not sure how to handle it correctly.
override fun getObjects(): Single<List<Object>> {
return db.objectDao().getObjectByUid(authPref.getUid())
.flattenAsObservable { items -> items }
.flatMap { setProps(it) }
.toList()
}
private fun setProps(obj: Object): Observable<Object> {
val propsA = db.propsADao().getProps(obj.id) // Single<List<A>>
val propsB = db.probsBDao().getProps(obj.id) // Single<B>
val result = propsA.flatMap { a ->
propsB.flatMap {
obj.propsA = a
obj.propsB = it
Single.just(obj)
}
}
return result.toObservable()
}