title: How to filter efficiently with optional params in Kotlin?
body: <p>I am working on <code>Kotlin</code> list <code>filter</code>. Let's say I have a list of <code>Worker</code> instances and I want to design a function which filters the list on condition for <code>startAge</code> and <code>maxSalary</code> <strong>nullable</strong> params.</p>
  <h3>Data class</h3>
  <pre><code>data class Worker(name:String?, age: Int?, salary: Int?){
  
  }
  </code></pre>
  <h3>Function filteredList()</h3>
  <pre><code>fun filterList(original: List&lt;Worker&gt;, startAge: Int?, maxSalary: Int?): List&lt;Student&gt;{
      val list = original.filter{
          it.age &gt;= startAge &amp;&amp; it.salary &lt;= maxSalary
      }
      return list
  }
  </code></pre>
  <p>At that point, I want to design the <code>filterList</code> function in such a way if any param is passed as a <code>null</code>, that condition should not be skipped. How do I do that? For example, calling with</p>
  <p><code>val list = filterList(original, null, 100)</code> should return list of workers whose max salary is <code>100</code> but does not matter the age.</p>
  <h3>My thought</h3>
  <p>In this particular problem I can choose default <code>startAge = Int.MAX_VALUE</code> and <code>maxSalary = Int.MIN_VALUE</code> when <code>null</code> is passed in params. But I think there can be many kind of conditional check inside filter (i.e compare dates, string equality check, evaluate expressions etc.) which might not always be possible to cover with <code>default</code> value. How can I get rid of this glitch?</p>