简体   繁体   English

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

[英]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 . 我刚看了杰克沃顿 与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? 使用带有ObservableTransformercompose()和带有两个Observable的简单flatMap()有什么区别?

There is a good explanation, from Daniel Lew, about the differences. Daniel Lew对这些差异有一个很好的解释。 In short: 简而言之:

The difference is that compose() is a higher level abstraction: it operates on the entire stream, not individually emitted items. 不同之处在于compose()是一个更高级别的抽象:它在整个流上运行,而不是单独发出的项目。

For more details look at the complete explanation in this article (in the section named What About flatMap()? ) 欲了解更多详细信息,看完整的解释在这篇文章中 (在名为怎么样flatMap()的部分?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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