我有一些其他人編寫的代碼。你能幫我理解這段代碼嗎?Scala:模式匹配代碼
def sameCodeForTwoYears(list: List[(LocalDate, String)]): List[(LocalDate, String)] = {
list match {
case x :: Nil => List.empty
case x :: xs => if (xs.head._1.minusYears(2).isAfter(x._1) && x._2 == xs.head._2) {
List(x, xs.head)
} else sameCodeForTwoYears(xs)
case Nil => List.empty
}
}
thanx ,.很好的解釋 –