title: How Can I Merge a Single<List<List<T>>> Into a List<T> with RxJava 2?
body: <p>What I want to do is hit an endpoint to get a list of users, that returns <code>Single&lt;List&lt;User&gt;&gt;</code>. Next, I want to grab the first three users and hit another endpoint to get all of their posts <code>Single&lt;List&lt;Post&gt;&gt;</code>. Finally I want to display a <code>Toast</code> that has the <em>total number of posts</em> for all of the first 3 users.</p>
  
  <p>I've been able to achieve it with the <code>flatten()</code> function available in Kotlin. However, I'd like to know how to do this using only RxJava 2. Is it possible? Thanks.</p>
  
  <pre><code>...
  
  getPostsForFirstThreeUsers()
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(
          { posts -&gt; toast("There are: ${posts.flatten().size} posts") },
          { ex -&gt; Timber.e(ex, "there was an error processing the request") }
                )
  
  
  
  fun getFirstThreeUsers(): Flowable&lt;User&gt; {
      return getAllUsers()
              .flattenAsFlowable { users -&gt; users }
              .doOnNext { Timber.i("a user: ${it.username}") }
              .take(3)
  }
  
  fun getPostsForFirstThreeUsers(): Single&lt;List&lt;List&lt;Post&gt;&gt;&gt; {
      return getFirstThreeUsers()
              .flatMapSingle { api.getUsersPosts(it.id) }
              .doOnNext { Timber.i("number of posts: ${it.size}") }
              .toList()
  }
  </code></pre>