title: What is a case where `thenApply()` vs. `thenCompose()` is ambiguous despite the return type of the lambda?
body: <p>I'm learning about <code>CompletableFuture</code>s.</p>
  
  <p><strong>I am not asking about <a href="https://stackoverflow.com/questions/43019126/completablefuture-thenapply-vs-thencompose">the difference between <code>thenApply()</code> and <code>thenCompose()</code></a>.</strong> Instead, I want to ask about a code "scent" that doesn't feel right, and what might actually justify it.</p>
  
  <p>From the usages of <code>CompletableFuture</code>s I've seen so far, it seems you'd never have this:</p>
  
  <pre><code>CompletableFuture&lt;String&gt; foo = getSomething().thenApply((result) -&gt; { ... });
  </code></pre>
  
  <p>Nor this:</p>
  
  <pre><code>String foo = getSomething().thenCompose((result) -&gt; { ... });
  </code></pre>
  
  <p>To return a future, you have to use <code>thenCompose()</code>, and otherwise <code>thenApply()</code>.</p>
  
  <p>From experience though, it seems weird that language didn't devise a way to eliminate making this unambiguous choice every time. For example, couldn't there have been a single method <code>thenDo()</code> whose return type is inferred (during compile-time) from the <code>return</code> within the lambda? It could then be given <code>thenApply</code> or <code>thenCompose</code>-like properties at compile-time as well.</p>
  
  <p>But I'm sure there's a good reason for having separate methods, so I'd like to know why.</p>
  
  <ul>
  <li><p>Is it because it's dangerous or not possible to infer return types from lambdas in Java? (I'm new to Java as well.)</p></li>
  <li><p>Is it because there is a case in which a single method would indeed be ambiguous, and the only solution is to have separate methods? (I'm imagining maybe, nested <code>CompletableFuture</code>s or complicated interfaces and generics.) If so, can someone provide a clear example?</p></li>
  <li><p>Is it for some other reason or documented recommendation?</p></li>
  </ul>