以下代码无法编译:
scala> case class T3( x:Int,y:Int,z:Int) { def foreach[U](f:((Int,Int,Int)) => U) = f( (x,y,z) ) }
defined class T3
scala> for ( (x,y,z) <- T3(1,2,3) ) { println (x,y,z) }
<console>:10: error: value filter is not a member of T3
for ( (x,y,z) <- T3(1,2,3) ) { println (x,y,z) }
^
我不明白为什么这段代码需要过滤器,因为它总是匹配的?
编辑 对于我的问题,添加一个无意义的过滤器实现就足够了:
scala> case class T3( x:Int,y:Int,z:Int) { def foreach[U](f:((Int,Int,Int)) => U) = f( (x,y,z) )
| def filter(p: ((Int,Int,Int)) => Boolean) = this }
defined class T3
scala> for ( (x,y,z) <- T3(1,2,3) ) { println (x,y,z) }
(1,2,3)
scala>