1
votes

EDIT / UPDATE: PROBLEM IS FIXED!

This is kinda strange as iterating over collections in Scala is usually straight forward but I do get a compile error while using an double array from a case class. The error says:

 error: value foreach is not a member of Array[Double] for(d <- data.data_arr) 

okay, here is the case class:

case class StatsData (name: String,
                  timeUnit: TimeUnit,
                  data_arr: Array[Double],
                  min: Double,
                  max: Double){}

And here is the critical point:

  /*Doesn't work */ 
 for(d <- data.data_arr) {         
  println(d) // can't fetch value d here   
  number = new Number(col, row, d)
 }

Strange thing is, no matter what kind of iteration I'm using, it simply doesn't work. For example using array index

 for (i <- data_arr.length-1)

as well as converting the array to a sequence throws exactly the same error as above;

for(d <- data.data_arr.toSeq)

What am I doing wrong?

Thanks for any help on this matter.

EDIT / UPDATE: PROBLEM IS FIXED!

As it turns out, the cause of the problem was an issue within IntelliJ's Project settings or structure, I cannot say it for certain but it was all solved by creating a new project. The same code runs now perfectly fine. Sorry for that but nearly all of the post has helped me to trace the issue down.

@yakshaver

What is the "yield" expression exactly used for?

Thanks for all the help.

1
Can't reproduce the issue. Have you done a clean compile?Kim Stebel
yes, I did several clean compiles before asking, even restarted InteliJ but the issue remains the same.Marvin.Hansen
foreach is a member of ArrayOps not Array—but that's weird that it isn't finding the implicit conversion from Predef. Try explicitly importing scala.Predef.doubleArrayOps (or calling it directly) and see if that fixes the problem. That should help with the diagnosis...DaoWen
That makes it really funny because importing Scala.Predef.doubleArrayOps gives me the following error: error: value doubleArrayOp is not a member of object Predef import scala.Predef.doubleArrayOpMarvin.Hansen
You forgot the s: scala.Predef.doubleArrayOpsDaoWen

1 Answers

0
votes

Both

Array(1, 2, 3) foreach println

and

for(i <- Array(1, 2, 3)) yield i

and

for(i <- Array(1, 2, 3)) { println(i) }

work nicely in 2.10.0-RC3 for me.