Core Operators:Mapping and Filtering
In RxJava,you must forget about mutating data structures internally:modifying variables outside of stream is considered very nonidiomatic and dangerous.
1、filter()
2、1-to-1 Transformations Using map()
All types wrapped with Observable should be immutable for all practical application
3、Wrapping Up Using flatMap()
You use flatMap() for the following situations:
- The result of transformation in map() must be an Observable()
- You need a one-to-many transformation,a single event is expanded into multiple sub-events.
flatMapIterable()
public final <R> Observable<R> flatMap(
Func1<? super T, ? extends Observable<? extends R>> onNext,
Func1<? super Throwable, ? extends Observable<? extends R>> onError,
Func0<? extends Observable<? extends R>> onCompleted)
If you don`t know how to handle an exception,let your supervisor(e.g.,the calling method,parent task ,or downstream Observable) make a decision.
4、Postponing Events Using the delay() Operator
5、Order of Events After flatMap()
6、Preserving Order Using concatMap()
Controlling the concurrency of flatMap()
public final <R> Observable<R> flatMap(Func1<? super T, ? extends Observable<? extends R>> func, int maxConcurrent)
Attention
flatMap() uses the merge() operator internally that subscribes to all sub-Observables at the same and does not make any distinction between.On the other hand,concat() subscribes only to the first underflying Observable and continues with the second one when the first one completes.
最后,安利一款自己写的基于MVP的Android开发框架
https://github.com/sxenon/Pure
欢迎大家拍砖,如果觉得好,麻烦多多star