I have the following:
samples.sliding(2).foreach{case List(a, b)=> printf("%x %x\n", a.value, b.value)}
I know that the single ‘case’ will match all the possible values but I get a ‘match is not exhaustive’ warning. The Scala book explains where to put the @unchecked annotation on a normal fully-specified match expression, but not for the form above. How do I annotate the above to stop the compiler from complaining?
@uncheckedis only defined for the selector in a match operation, not for arbitrary functions. So you couldbut that is rather a mouthful.
Alternatively, you could create a method that unsafely converts a partial function to a complete one (which actually just casts to the function superclass of
PartialFunction):and then you can
and you don’t have any warnings because it was expecting a partial function.