title: Convert Observable of List to List of Observables and merge in RxJava
body: <p>I'm learning Java with Android by creating Hacker News reader app.</p>
  
  <p>What I'm trying to do is:</p>
  
  <ol>
  <li>Send a request to <code>/topstories</code>, return <code>Observable&lt;List&lt;int&gt;&gt;</code>, emit when 
  request finishes.</li>
  <li>Map each <code>storyId</code> to <code>Observable&lt;Story&gt;</code></li>
  <li>Merge Observables into one entity, which emits <code>List&lt;Story&gt;</code>, when all requests finishes.</li>
  </ol>
  
  <p>And to the code:</p>
  
  <pre><code>  private Observable&lt;Story&gt; getStoryById(int articleId) {
      BehaviorSubject&lt;Story&gt; subject = BehaviorSubject.create();
      // calls subject.onNext on success
      JsonObjectRequest request = createStoryRequest(articleId, subject);
      requestQueue.add(request);
      return subject;
    }
  
    public Observable&lt;ArrayList&lt;Story&gt;&gt; getTopStories(int amount) {
      Observable&lt;ArrayList&lt;Integer&gt;&gt; topStoryIds = (storyIdCache == null)
        ? fetchTopIds()
        : Observable.just(storyIdCache);
  
      return topStoryIds
        .flatMap(id -&gt; getStoryById(id))
        // some magic here
    }
  </code></pre>
  
  <p>Then we would use this like:</p>
  
  <pre><code>getTopStories(20)
    .subscribe(stories -&gt; ...)
  </code></pre>