In my project, I use RxJava/RxKotlin bindings to communicate with REST API. The API sometimes returns a list of elements, that need to be altered/mapped, before I can use them.
Currently, mapping of these elements is done by nested .map()
and .apply()
functions, like this:
fun getSampleObjects(): Single<List<SampleObject>> =
sampleService.getSampleObjects()
.map { list ->
list.map { sampleObject ->
sampleObject.apply {
sampleProperty = otherSampleService.getSampleProperty()
}
}
}
where sampleService.getSampleObjects()
returns and RxKotlin Single<List<SampleObject>>
I'm looking for an easier-to-read and more efficient way to archive the same result, possibly without the need to alter data models.