title: How can i remap a list based on different conditions in scala?
body: <p>I have a list of custom objects (Buffer [CustomObject] ) on which I'm applying .map, in order to return a list of (String,Boolean,Boolean,Boolean) only if at least one of the conditions on the element are met. The string is taken inside the custom object. The code is something like this :</p>
  <pre><code>list.map{ item=&gt;
    val string = item.string
    val boolean1 = true
    val boolean2 = true
    val boolean3 = true
  
    //-- some code to check the conditions -- //
  
    if (!boolean1 || !boolean2 || !boolean3)
      (string,boolean1,boolean2,boolean3)
    else
      null
  }
  </code></pre>
  <p>The issue with this is that the list obviously contains some null values, and I need to remove them later. I also tried to use .collect() but without success, given that the conditions are more than one and must be checked with some code. I know I could use maybe a couple of .filter and .map in order to achieve this but my goal is to do everything in one iteration. Can you help me?
  Thanks</p>
  <p>Edit: found a &quot;partial&quot; solution, basically you can return an option and using .flatten or a .flatMap that automatically removes None values.</p>
  <pre><code>list.flatMap{ item=&gt;
    val string = item.string
    val boolean1 = true
    val boolean2 = true
    val boolean3 = true
  
    //-- some code to check the conditions -- //
  
    if (!boolean1 || !boolean2 || !boolean3)
      Some (string,boolean1,boolean2,boolean3)
    else
      None
  }
  </code></pre>
  <p>But it is a kind of &quot;ugly&quot; solution, is there a more &quot;elegant&quot; one?</p>