【问题标题】:Compilation error during the filtering of zipped arrays using nested function使用嵌套函数过滤压缩数组期间的编译错误
【发布时间】:2014-10-21 13:44:49
【问题描述】:

我正在尝试使用嵌套函数过滤压缩数组,但出现与变量“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])=>
                                              ^

我不知道此错误的根源,因此我们将不胜感激。

干杯。

【问题讨论】:

    标签: scala scala-collections scala-2.10


    【解决方案1】:

    你错过了case。它应该看起来更像这样:

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

    类型参数会产生一个没有结果的类型测试警告,所以我省略了它们。如果您愿意,可以将case (one, two) 替换为case mergedRow,但是对onetwo 进行操作比mergedRow._1mergedRow._2 更干净。

    【讨论】:

    • 确实使用 case(one,tow) 比 mergeRow._1 和 mergeRow._2 干净得多。谢谢你的帮助:)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-25
    • 1970-01-01
    相关资源
    最近更新 更多