Don't break the chain: use RxJava's compose() operator
One nice aspect of RxJava is that you can see how data is transformed through a series of operators:
Observable.from(someSource) .map(data -> manipulate(data)) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(data -> doSomething(data));
What if you have a set of operators that you want to reuse for multiple streams? For example, I frequently use subscribeOn()
and observeOn()
because I want to process data in a worker thread then subscribe to it on the main thread. It'd be great if I could apply this logic to all my streams in a consistent, reusable manner.
Read full article from Don't break the chain: use RxJava's compose() operator
No comments:
Post a Comment