How to choose operator?
- Decision trees can help find the operators you need.
Decision tree
Create an Observable
- Generate a specific element: just
- After a delay: timer
- Pull elements from a sequence: from
- Repeatedly produce an element: repeatElement
- There is custom logic: create
- Generated every time you subscribe: deferred
- Every once in a while, an element is issued: interval
- After a delay: timer
- An empty sequence, only one completion event: empty
- A sequence not generated by any event: never
Create an Observable by combining other Observables
- If any Observable produces an element, it emits this element: merge
- Let these Observables emit elements one after another. After the last Observable element is sent, the next Observable-can start to emit elements: concat
- Combining multiple Observables elements
- When each Observable emits a new element: zip
- When any Observable emits a new element: combineLatest
After converting the elements of Observable, send them out
-
Direct conversion for each element: map
-
Convert to another Observable: flatMap
- Only receive the elements generated by the Observable converted by the latest element: flatMapLatest
- Each converted Observable generates elements in order: concatMap
-
Based on all traversed elements: scan
-
Every element that will be produced will be sent out after a delay: delay
Package the generated events into elements and send them out
- Package them into Event: materialize
- Then unpack it: dematerialize
Ignore all next events and only receive completed and error events: ignoreElements
Create a new Observable and add some elements in front of the original sequence: startWith
Collect elements from Observable, cache these elements and issue: buffer
Split Observable into multiple Observables: window
- Element-based common characteristics: groupBy
Only receive specific elements in Observable
- Issue the only element: single
Reissue certain elements from Observable
-
Filter out some elements by determining conditions: filter
-
Only send out the first few elements: take
-
Only emit a few elements of the tail: takeLast
-
Only emit the nth element: elementAt
-
Skip the first few elements
- Skip the first n elements: skip
- Skip the first few elements that satisfy the decision: skipWhile, skipWhileWithIndex
- Skip the first few elements generated in a certain period of time: skip
- Skip the first few elements until another Observable emits an element: skipUntil
-
Only take the first few elements
- Only take the first few elements that satisfy the decision: takeWhile, takeWhileWithIndex
- Only take the first few elements generated in a certain period of time: take
- Only take the first few elements until another Observable emits an element: takeUntil
-
Sampling Observable periodically: sample
-
Emit those elements. Within a certain time after these elements are generated, no new elements are generated: debounce
-
No new elements are issued until the value of the element changes: distinctUntilChanged
- And provide the judging function of whether the elements are equal: distinctUntilChanged
-
When you start to issue elements, subscribe after a delay: delaySubscription
-
From some Observables, only the first Observable that produces the element: amb
Evaluate all elements of Observable
- And apply the aggregation method to each element. After applying the aggregation method to all elements, the result is: reduce
- And apply the aggregation method to each element, and after applying the aggregation method each time, send out the result: scan
Convert Observable into other data structures: as ...
Want to apply operator to a Scheduler: subscribeOn
- Listening on a Scheduler: observeOn
When an event occurs in the Observable, take an action: do
Want Observable to emit an error event: error
- If no elements are generated within the specified time: timeout
Want to recover gracefully when an error occurs in Observable
- If no elements are generated within the specified time, switch to the alternative Observable: timeout
- If an error occurs, replace the error with an element: catchErrorJustReturn
- If an error occurs, switch to the alternative Observable: catchError
- If an error occurs, try again: retry
Create a Disposable resource so that it has the same lifetime as Observable: using
Create an Observable, until I notify it that it can produce elements, can not produce elements: publish
- And, even if you subscribe after generating the elements, you must send out all the elements: replay
- And, once all observers cancel the observation, he is released: refCount
- Notify that it can produce elements: connect