scala.sample 429 Bytes
Newer Older
Sergey's avatar
Sergey committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
class Date(y: Int, m: Int, d: Int) extends Ord:
  // previous decls here

  def <(that: Any): Boolean = that match
    case d: Date =>
      (year < d.year) ||
      (year == d.year && (month < d.month ||
                         (month == d.month && day < d.day)))

    case _ => sys.error("cannot compare " + that + " and a Date")
  end <
end Date

// From https://docs.scala-lang.org/tutorials/scala-for-java-programmers.html