title: Logical OR of multiple Optional instances?
body: <p>Is there a more elegant way to represent the following algorithm using the Java core API?</p>
  
  <pre><code>Optional&lt;Float&gt; input = Optional.of(A);
  Optional&lt;Float&gt; output = input.map(function1).map(function2);
  if (!output.isPresent())
  {
    output = input.map(function1).map(function2);
    if (!output.isPresent())
    {
      output = input.map(function3).map(function4);
        if (!output.isPresent())
          output = input.map(function5).map(function6);
    }
  }
  </code></pre>
  
  <p>That is, instead of nesting multiple invocations of <code>isPresent()</code> I'd like to invoke a method like <code>map()</code> but that would only get invoked if a value is absent.</p>
  
  <p>In an ideal world, I want to invoke something along the lines of:</p>
  
  <pre><code>Optional&lt;Float&gt; output = input.or(input.map(function1).map(function2), input.map(function2).map(function3), input.map(function4).map(function5));
  </code></pre>
  
  <p>This is what I've got so far, but can we do better?</p>
  
  <pre><code>public class Optionals
  {
      /**
       * @param &lt;T&gt;       the type of value returned by the Optionals
       * @param suppliers one or more suppliers that return a supplier
       * @return the first Optional that {@link Optional#isPresent() isPresent()}
       */
      public static &lt;T&gt; Optional&lt;T&gt; or(Supplier&lt;Optional&lt;T&gt;&gt;... suppliers)
      {
          for (Supplier&lt;Optional&lt;T&gt;&gt; supplier: suppliers)
          {
              Optional&lt;T&gt; candidate = supplier.get();
              if (candidate.isPresent())
                  return candidate;
          }
          return Optional.empty();
      }
  
      /**
       * Prevent construction.
       */
      private Optionals()
      {
      }
  }
  </code></pre>