title: What's the most elegant way to combine optionals?
body: <p>Here's what I've got so far:</p>
  
  <pre><code>Optional&lt;Foo&gt; firstChoice = firstChoice();
  Optional&lt;Foo&gt; secondChoice = secondChoice();
  return Optional.ofNullable(firstChoice.orElse(secondChoice.orElse(null)));
  </code></pre>
  
  <p>This strikes me as both hideous and wasteful. If firstChoice is present I am needlessly computing secondChoice.</p>
  
  <p>There's also a more efficient version:</p>
  
  <pre><code>Optional&lt;Foo&gt; firstChoice = firstChoice();
  if(firstChoice.isPresent()) {
   return firstChoice;
  } else {
   return secondChoice();
  }
  </code></pre>
  
  <p>Here I can't chain some mapping function to the end without either duplicating the mapper or declaring another local variable. All of this makes the code more complicated than the actual problem being solved.</p>
  
  <p>I'd much rather be writing this:</p>
  
  <pre><code>return firstChoice().alternatively(secondChoice());
  </code></pre>
  
  <p>However Optional::alternatively obviously doesn't exist. Now what?</p>