What is the difference between using compose () and plain flatMap ()?

I just watched the Jake Wharton State of Governing State conference with RxJava .

He suggests converting events from view to action in this way:

Observable<Event> events = RxView.clicks(view).map(__ -> new Event()); ObservableTransformer<Event, Action> action = events -> events.flatMap(/* ... */); events.compose(action).subscribe(); 

I would like to know the difference with this implementation:

 Observable<Event> events = RxView.clicks(view).map(__ -> new Event()); Observable<Action> action = events.flatMap(/* ... */); action.subscribe(); 

What is the difference between using compose() with an ObservableTransformer and a simple flatMap() with two Observables?

+5
source share
1 answer

There is a good explanation from Daniel Lew about the differences. Shortly speaking:

The difference is that compose () is an abstraction of a higher level: it works on the whole stream, and not on individual elements.

For more details, see the full explanation in this article (under "What is flatmap ()?)

+8
source

Source: https://habr.com/ru/post/1266760/


All Articles