簡體   English   中英

使用嵌套函數過濾壓縮數組期間的編譯錯誤

[英]Compilation error during the filtering of zipped arrays using nested function

我正在嘗試使用嵌套函數過濾壓縮數組,但出現了與變量“ mergedRow”類型有關的編譯錯誤

這是我的例子:

ScalaVersion = 2.10.4

val arrayOne : Seq[IndexedSeq[Double]] = Seq.empty
val arrayTow : Seq[IndexedSeq[String]]  = Seq.empty

(this.arrayOne , this.arrayTow).zipped.filter{
  mergedRow : (IndexedSeq[String], IndexedSeq[Double])=>

  // some processing
  true
}

編譯錯誤:

Error:(130, 51) type mismatch;
 found   : ((IndexedSeq[String], IndexedSeq[Double])) => Boolean
 required: (IndexedSeq[String], IndexedSeq[Double]) => Boolean
      mergedRow : (IndexedSeq[String], IndexedSeq[Double])=>
                                              ^

我不知道此錯誤的根源,因此將不勝感激。

干杯。

您缺少case 它看起來應該像這樣:

(arrayOne , arrayTwo).zipped.filter{
    case (one, two) =>
       // filter predicate
}

類型參數將產生無效的類型測試警告,因此我省略了它們。 如果願意,可以用case mergedRow替換case (one, two) ,但是對onetwo執行操作比mergedRow._1mergedRow._2干凈得多。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM