TheReturningVoid
TheReturningVoid

Reputation: 111

Iterate over Guava ImmutableList in Scala

I'm having trouble iterating over a ImmutableList from Guava in Scala. The only reason I'm working with them is because I'm working with code written in Java that uses the Guava API. However, the compiler doesn't seem to like it. Here's my code:

for (blockData: IBlockData <- block.P.a) {
  *insert actions here*
}

The compiler errors with this:

Error:(24, 43) value filter is not a member of com.google.common.collect.ImmutableList[net.minecraft.server.v1_8_R3.IBlockData]
for (blockData: IBlockData <- block.P.a) {
                      ^

Any help is greatly appreciated. Thanks!

Upvotes: 1

Views: 499

Answers (1)

Noah
Noah

Reputation: 13959

To use Scalas for expression the object has to implement flatMap and filter which guava collections do not. Scala comes bundled with Java converters, this should work:

import collection.JavaConverters._
for (blockData: IBlockData <- block.P.a.asScala) {
  *insert actions here*
}

Upvotes: 3

Related Questions