title: How to divide 1 completablefuture to many completablefuture in stream?
body: <p>For example I have such methods:</p>
  
  <pre><code>public CompletableFuture&lt;Page&gt; getPage(int i) {
      ...
  }
  public CompletableFuture&lt;Document&gt; getDocument(int i) {
      ...
  }
  public CompletableFuture&lt;Void&gt; parseLinks(Document doc) {
      ...
  }
  </code></pre>
  
  <p>And my flow:</p>
  
  <pre><code>List&lt;CompletableFuture&gt; list = IntStream
      .range(0, 10)
      .mapToObj(i -&gt; getPage(i))
  
      // I want method like this:
      .thenApplyAndSplit(CompletableFuture&lt;Page&gt; page -&gt; {
          List&lt;CompletableFuture&lt;Document&gt;&gt; docs = page.getDocsId()
              .stream()
              .map(i -&gt; getDocument(i))
              .collect(Collectors.toList());
          return docs;
      })
      .map(CompletableFuture&lt;Document&gt; future -&gt; {
          return future.thenApply(Document doc -&gt; parseLink(doc);
      })
      .collect(Collectors.toList());
  </code></pre>
  
  <p>It should by something like <code>flatMap()</code> for <code>CompletableFuture</code>, so I want to implement this flow:</p>
  
  <pre><code>List&lt;Integer&gt; -&gt; Stream&lt;CompletableFuture&lt;Page&gt;&gt;
                -&gt; Stream&lt;CompletableFuture&lt;Document&gt;&gt;
                -&gt; parse each
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>Stream&lt;CompletableFuture&lt;Page&gt;&gt; pagesCFS = IntStream
          .range(0, 10)
          .mapToObj(i -&gt; getPage(i));
  
  Stream&lt;CompletableFuture&lt;Document&gt;&gt; documentCFS = listCFS.flatMap(page -&gt; {
      // How to return stream of Document when page finishes?
      // page.thenApply( ... )
  })
  </code></pre>