title: Existing way to Java map Optional<> onto object instead of to another object?
body: <p>I'm familiar with <code>Optional.map(mapper)</code>, which maps an optional object to something else. So if I wanted to do something with an optional <code>Foo</code> and a non-optional <code>Bar</code>, I could do:</p>
  
  <pre><code>Optional&lt;Foo&gt; foobar = foo.map(foo -&gt; foo.addBar(bar))
  </code></pre>
  
  <p>This works sort of like:</p>
  
  <pre><code>Optional&lt;Foo&gt; foobar = foo.isPresent() ? Optional.of(foo.get().add(bar)) : Optional.empty();
  </code></pre>
  
  <p>But I'm seeing a recurring pattern in which <em><code>bar</code></em> is optional. The functionality I want to replicate looks something like this:</p>
  
  <pre><code>Foo foobar = bar.isPresent() ? foo.add(bar.get()) : foo;
  </code></pre>
  
  <p>In other words, if the <em>other</em> thing is present, let me do something with it in regards to my existing thing; otherwise, just give me my existing thing back.</p>
  
  <p>I could imagine making my own <code>Optionals.doIfOtherPresent(T object, Optional&lt;U&gt; optional, BiFunction&lt;? super T, ? super U, ? extends T&gt; fn)</code>. I would use it like this:</p>
  
  <pre><code>Foo foobar = doIfOtherPresent(foo, bar, foo::add);
  </code></pre>
  
  <p>Is there something in the Java library that does this already?</p>