title: How to do an action if an optional boolean is true?
body: <p>In Java 8, I have a variable, holding an optional boolean.</p>
  
  <p>I want an action to be executed, if the optional is not empty, and the contained boolean is true.</p>
  
  <p>I am dreaming about something like <code>ifPresentAndTrue</code>, here a full example:</p>
  
  <pre><code>import java.util.Optional;
  
  public class X {
    public static void main(String[] args) {
      Optional&lt;Boolean&gt; spouseIsMale = Optional.of(true);
      spouseIsMale.ifPresentAndTrue(b -&gt; System.out.println("There is a male spouse."));
    }
  }
  </code></pre>