I have the List of SourceObjects and I need to convert it to the List of ResultObjects.
I can fetch one object to another using method of ResultObject:
c
As an extension to Noel great answer. Let's say transformation also depends on some server data that might change during subscription. In that case use flatMap + scan.
As a result when id list changes, transformations will restart anew. And when server data changes related to a specific id, single item will be retransformed as well.
fun getFarmsWithGroves(): Observable> {
return subscribeForIds() //may change during subscription
.switchMap { idList: Set ->
Observable.fromIterable(idList)
.flatMap { id: String -> transformId(id) } //may change during subscription
.scan(emptyList()) { collector: List, candidate: FarmWithGroves ->
updateList(collector, candidate)
}
}
}