title: Test only if variable is not null in if statement
body: <p>I have the following method where I want to test the <code>event.status</code> property only if <code>status</code> has been passed in: </p>
  
  <pre><code>def findEvent(String desc, String status = null, Collection events) {
          return events.find {
              it.description == desc &amp;&amp; \\If status is not null: it.status == status
          }
  
          throw new Exception("Review Event Record Not Found: ${desc}")
  }
  </code></pre>
  
  <p>I thought it could be done like this, but it doesn't seem to work:</p>
  
  <pre><code>def findEvent(String desc, String status = null, Collection events) {
          return events.find {
              it.description == desc &amp;&amp; (status != null ?: {it.status == status})
          }
  
          throw new Exception("Review Event Record Not Found: ${desc}")
  }
  </code></pre>
  
  <p>Is there any way this could be done? Or do I have to go back to something like this:</p>
  
  <pre><code>if (status != null) {
      return events.find {
          it.description == desc &amp;&amp; it.status == status
      }
  } else if (status == null) {
      return events.find {
          it.description == desc
      }
  }
  </code></pre>
  
  <p>Is there some kind of best practice?</p>