Why is this Scala for loop translation not equivalent?

Viewed 75

I tried writing this code

val req: mutable.Buffer[InterfaceHttpData] = /*...*/
for (attr: Attribute <- req) {
  println(attr.getValue())
}

This gives me the following error:

type mismatch;
 found   : io.netty.handler.codec.http.multipart.Attribute => Unit
 required: io.netty.handler.codec.http.multipart.InterfaceHttpData => ?

I've read through the specs and as far as I can tell, this for loop should be equivalent to the following.

req.withFilter { case attr: Attribute => true; case _ => false }.foreach {
  case attr: Attribute => println(attr.getValue())
}

This compiles cleanly. Am I misunderstanding how the for loop transformation is done?

1 Answers
Related