简体   繁体   中英

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

I just watched the conference by Jake Wharton The State of Managing State with RxJava .

He proposes to transform the 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 a compose() with an ObservableTransformer and a simple flatMap() with two Observable?

There is a good explanation, from Daniel Lew, about the differences. In short:

The difference is that compose() is a higher level abstraction: it operates on the entire stream, not individually emitted items.

For more details look at the complete explanation in this article (in the section named What About flatMap()? )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM