Combining producers (Observable/Flowable)
While developing applications, it's a common situation to combine data from multiple sources before using them. One such situation is when you are building some offline application following an offline-first approach, and you want to combine the resultant data you got from the HTTP call with the data from the local database.
Now, without wasting much time, let's take a look at the operators that can help us combine producers:
startWith()
merge()
,mergeDelayError()
concat()
zip()
combineLatest()
Basically, there are a few mechanisms to combine producers (Observables/Flowables). They are as follows:
- Merging producers
- Concatenating producers
- Ambiguous combination of producers
- Zipping
- Combine latest
We will discuss all the previously mentioned techniques to combine producers in this chapter. However, let's start with an operator that we are already aware of.
The startWith operator
We got introduced to the startWith
operator in the previous chapter, but there's still...