kioba
08/02/2017, 9:14 AMFlowable.zip<User, Comments, Pair<User, Comments>>(
postService.getUser(postId),
postService.getCommentsByPostId(postId),
BiFunction { user, comments -> Pair(user, comments) })
.subscribeOn(<http://Schedulers.io|Schedulers.io>())
.map { (first, second) -> Triple(first, second, ExtraDatas()) }
.subscribe({
Log.d("MainActivity", "OnNext")
}, {
Log.d("MainActivity", "OnError")
}, {
Log.d("MainActivity", "OnComplete")
})
Use the zip
or zipWith
functions to achieve your goal if the retrofit2 calls dont depent on each other. You can find out more here:
http://reactivex.io/documentation/operators/zip.html
after that map the data from the server with the mainActivity data together. Thats easy as well
and finally Kotlin has a very beautiful syntax for labdas so i would encourage you to use them with the specific subscribe function:
http://reactivex.io/RxJava/javadoc/io/reactivex/Flowable.html#subscribe(io.reactivex.functions.Consumer,%20io.reactivex.functions.Consumer,%20io.reactivex.functions.Action)