type Occurrences = List[(Char, Int)]
val lard = List(('a', 1), ('d', 1), ('l', 1), ('r', 1))
val r = List(('r', 1))
def subtract2(x: Occurrences, y: Occurrences): Occurrences =
x.foldLeft(List[(Char, Int)]())({case (acc, list) if(!(y.contains(list))) => acc.::(list)})
subtract2(lard, r)
scala.MatchError: (List(),(a,1)) (of class scala.Tuple2)
at forcomp.A$A183$A$A183$$anonfun$subtract2$1.apply(temp.sc:11)
at forcomp.A$A183$A$A183$$anonfun$subtract2$1.apply(temp.sc:11)
at scala.collection.LinearSeqOptimized$class.foldLeft(temp.sc:120)
at scala.collection.immutable.List.foldLeft(temp.sc:80)
at forcomp.A$A183$A$A183.subtract2(temp.sc:11)
at #worksheet#.#worksheet#(temp.sc:14)
いただきました。このエラーの理由を投げ?私はすべての問題が短所であることを、仮定が、より正確に、私は
をあなたの答えは、技術的な問題(差分を取得)を解いたが(マッチが失敗した理由)質問に答えていません。それでも私は人々が答えを奨励し、投票しようとしていないと思うので+1します –