title: Conditional application of `filter`/`where` to a Spark `Dataset`/`Dataframe`
body: <p>Hi folks I have a function that loads a data set from some S3 locations and returns the interesting data</p>
  
  <pre><code>private def filterBrowseIndex(spark: SparkSession, s3BrowseIndex: String, mids: Seq[String] = Seq(), indices: Seq[String] = Seq()): Dataset[BrowseIndex] = {
  import spark.implicits._
  
  spark
    .sparkContext.textFile(s3BrowseIndex)
    // split text dataset
    .map(line =&gt; line.split("\\s+"))
    // get types for attributes
    .map(BrowseIndex.strAttributesToBrowseIndex)
    // cast it to a dataset (requires implicit conversions)
    .toDS()
    // pick rows for the given marketplaces
    .where($"mid".isin(mids: _*))
    // pick rows for the given indices
    .where($"index".isin(indices: _*))
  </code></pre>
  
  <p>}</p>
  
  <p>This implementation will filter everything out if someone provides <code>mids = Seq()</code> or <code>indices = Seq()</code>. I on the other hand would like the semantics to be "apply this where clause only if <code>mids</code> is not empty" (same for <code>indices</code>) so that no filtering happens if the user of the function provides empty sequences.</p>
  
  <p>Is there a nice functional way to do that?</p>