使用 compose() 和简单的 flatMap() 有什么区别?

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

我刚看了 Jake Wharton The State of Managing State with RxJava 的会议。

他建议以这种方式将事件从视图转换为行动:

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

我想知道这个实现的区别:

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?

Daniel Lew 对这些差异做了很好的解释。简而言之:

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

有关详细信息,请参阅 this article 中的完整说明(在名为 What About flatMap()? 的部分)