title: Add to list if value is not null
body: <p>I have the function that could return null value:</p>
  
  <pre class="lang-scala prettyprint-override"><code>def func(arg: AnyRef): String = {
  ...
  }
  </code></pre>
  
  <p>and I want to add  the result to list, if it is not null:</p>
  
  <pre class="lang-scala prettyprint-override"><code>...
  val l = func(o)
  if (l != null)
    list :+= l
  ....
  </code></pre>
  
  <p>or</p>
  
  <pre class="lang-scala prettyprint-override"><code>def func(arg: AnyRef): Option[String] = {
  ...
  }
  </code></pre>
  
  <pre class="lang-scala prettyprint-override"><code>...
  func(o).filter(_ != null).map(f =&gt; list :+= f)
  ...
  </code></pre>
  
  <p>But it looks too heavy.</p>
  
  <p>Are there any better solutions?</p>