2
我列出與元組列表(字符,智力)像階過濾元組的列表
val raw = List(List((a,0), (b,0)), List((a,1), (b,0)), List((a,2), (b,0)), List((a,0), (b,1)), List((a,1), (b,1)), List((a,2), (b,1)), List((a,0), (b,2)), List((a,1), (b,2)), List((a,2), (b,2)))`
我想篩選出與其中int是0,所以結果應該所有元組的列表是:
List(List(), List((a,1)), List((a,2)), List((b,1)), List((a,1), (b,1)), List((a,2), (b,1)), List((b,2)), List((a,1), (b,2)), List((a,2), (b,2)))
我試圖做一個地圖,然後過濾,但編譯器與incompatible types: ((Int, Char) => Boolean expected but found ((Int, Char) => Unit)
raw.map(_.filter(tuple => match {
(_,0) => false
(_,_) => true
})
W¯¯抱怨趁着我去錯
謝謝由於經常使用Scala:更少的代碼達到最佳效果。 –