title: Stream till value found - optional
body: <p>I want to terminate execution of stream when found first value. However, when I run code below it shows up that two methods are called even if value is present from <em>first</em> method.   </p>
  
  <pre><code>public static void main(String[] args) {
  
          Optional&lt;String&gt; s = Stream.of(first(), second())
                  .filter(Optional::isPresent)
                  .findFirst()
                  .flatMap(Function.identity());
  
          System.out.println(s.get());
      }
  
      private static Optional&lt;String&gt; first() {
          System.out.println("first");
          return Optional.of("someValue");
      }
  
      private static Optional&lt;String&gt; second() {
          System.out.println("second");
          return Optional.empty();
      }
  </code></pre>
  
  <p>I checked in docs that:</p>
  
  <ol>
  <li>isPresent</li>
  </ol>
  
  <blockquote>
    <p>Return {@code true} if there is a value present, otherwise {@code
    false}.</p>
  </blockquote>
  
  <ol start="2">
  <li>findFirst()</li>
  </ol>
  
  <blockquote>
    <p>Returns an {@link Optional} describing the first element of this
    stream, or an empty {@code Optional} if the stream is empty.  If the
    stream has no encounter order, then any element may be returned.</p>
  </blockquote>
  
  <p>So the first condition it met, and the second seems to be also fulfilled cause it returns: </p>
  
  <pre><code>first
  second
  someValue
  </code></pre>
  
  <p>How to quit execution if first value present, and not execute <em>second</em> method?</p>