简体   繁体   English

使用嵌套函数过滤压缩数组期间的编译错误

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

I'm trying to filter zipped arrays using nested function, but I have got a compilation error related to the type of the variable "mergedRow" 我正在尝试使用嵌套函数过滤压缩数组,但出现了与变量“ mergedRow”类型有关的编译错误

Here is my example : 这是我的例子:

ScalaVersion = 2.10.4 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
}

The compilation error : 编译错误:

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

I don't know the origin of this error, so every help will be appreciated. 我不知道此错误的根源,因此将不胜感激。

Cheers. 干杯。

You're missing case . 您缺少case It should look more like this: 它看起来应该像这样:

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

The type arguments will produce a fruitless type test warning, so I omitted them. 类型参数将产生无效的类型测试警告,因此我省略了它们。 You can replace case (one, two) with case mergedRow if you wish, but doing operations on one and two is much cleaner than mergedRow._1 and mergedRow._2 . 如果愿意,可以用case mergedRow替换case (one, two) ,但是对onetwo执行操作比mergedRow._1mergedRow._2干净得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM