4

I have a fold operation something like the following:

val ops: Seq[Op] ...
(x /: ops) { case (y, MyOp(z)) =>
...
}

An Op can have many types other than MyOp but I know in this instance that the ops are all MyOps so I want to add an @unchecked annotation to removed the compiler warning.

Where should I place the @unchecked in this example?

user79074
  • 4,937
  • 5
  • 29
  • 57

1 Answers1

2

Try

(x /: ops)((y0, op) => 
  ((y0, op): @unchecked) match { 
    case (y, MyOp(z)) => ??? 
  }
)

https://www.scala-lang.org/files/archive/spec/2.11/11-annotations.html#scala-compiler-annotations

Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66
  • It makes the code very cumbersome to have to add that extra block I find. Its a pity there's not a cleaner way. – user79074 Mar 13 '19 at 15:56