title: Scala: elegant way to use require to validate multiple options?
body: <p>I have two solutions for this problem. I do not like both of them so I was wondering if there's a more elegant solution.</p>
  
  <pre><code>import java.util.Date
  import scala.math.Ordered.orderingToOrdered
  
  // Solution # 1:
  case class A(startDate: Option[Date] = None,
               endDate: Option[Date]   = None) {
    require(if (startDate.isEmpty &amp;&amp; endDate.isEmpty) false else true, 
            "Either startDate or endDate must be defined")
    require(if (startDate.isDefined &amp;&amp; endDate.isDefined) startDate.get &lt; endDate.get else true,  
            s"startDate:${startDate.get} must be less than endDate:${endDate.get}")
    // Problem: multiple checks using isEmpty and isDefined followed by .get
  }
  
  // Solution # 2:
  case class B(startDate: Option[Date] = None,
               endDate: Option[Date]   = None) {
    val (requirement, msg) = (startDate, endDate) match {
      case (None, None)                  =&gt; false -&gt; "Either startDate or endDate must be defined"
      case (Some(s), Some(e)) if (s &gt; e) =&gt; false -&gt; s"startDate:$s must be less than endDate:$e"
      case _                             =&gt; true  -&gt; "OK" // Problem: redundant statement
    }
    require(requirement, msg)
  }
  </code></pre>
  
  <p>Conditions: </p>
  
  <ol>
  <li>Both startDate or endDate can be None </li>
  <li>startDate cannot be greater than endDate</li>
  </ol>