flatMap, concatMap – In details
As promised in the previous chapter, now we will take a deeper dive into the flatMap
and concatMap
operators, as, by now, we have already gained some sort of expertise on the merge
and concat
operators and know the differences between them.
Let's start with the differences between flatMap
and concatMap
, after which, we will also discuss their ideal implementation scenarios. We will also discuss some of their variants to know them better.
In the previous chapter, we mentioned that flatMap
internally uses the merge
operator and concatMap
internally uses the concat
operator. However, what difference does that make? You just learned the differences between the merge
and the concat
operator, but what is the point of having two separate mapping operators based on them? So, let's start with an example. We will see an example with flatMap
, and then we will try to implement the same with concatMap
:
fun main(args: Array<String>) { Observable.range(1,10...