title: How to flatMap a Flux with a Mono?
body: <p>I am building a service that call two REST resources. The first call retrieve a list of items and the second get the details of each item in the list.</p>
  
  <pre><code>Flux&lt;Result&gt; search(query) {
      return client.post().uri("/search")
         .body(BodyInserters.fromObject(query))
         .retrieve()
         .bodyToMono(SearchResults.class)
         .flatMapIterable(r -&gt; r.getResults())
         .flatMap(this::detail);
  }
  
  Mono&lt;Detail&gt; detail(result) {
      return client.get().uri("/detail/{id}", result.id)
          .retrieve()
          .doOnNext(System.out::println))
          .bodyToMono(Detail.class);
  }
  </code></pre>
  
  <p>I can see that the <code>GET /detail/{id}</code> request is sent, but the <code>doOnNext</code> in the <code>this::detail</code> block is never called from my test:</p>
  
  <pre><code>StepVerifier.create(target.search(query))
      .assertNext(d -&gt; {
          assertThat(d.getField()).isEqualTo("detailed");
      })
      .verifyComplete();
  </code></pre>
  
  <p>And this test fail with :</p>
  
  <blockquote>
    <p>java.lang.AssertionError: expectation "assertNext" failed (expected: onNext(); actual: onComplete())</p>
  </blockquote>
  
  <p>I am a bit stuck at this stage, the Reactor documentation use <code>flatMap</code> for this kind of case and it looks like the sub request (for details) is sent. While looking at Wirmock, I see that he is able to return a response but then I have nothing more.</p>
  
  <p>Does anyone has an idea of what goes wrong ?</p>