Given the following code snippelt:
import scala.util.Try
def foo(x:Int) : (Int, String) = {
(x+1, x.toString)
}
def main(args: Array[String]) : Unit = {
val r1: Try[(Int, String)] = for {
v <- Try { foo(3) }
} yield v
val r2: Try[(Int, String)] = for {
(i, s) <- Try { foo(3) } // compile warning refers to this line
} yield (i, s)
}
1. Why does a compile of the above code throw the following warning?
`withFilter' method does not yet exist on scala.util.Try[(Int, String)], using `filter' method instead
[warn] (i, s) <- Try { foo(3) }
[warn] ^
[warn] one warning found
2. Why is withFilter
used at all when extracting to a tuple?
Update
- The warning occurs with Scala 2.10.5
- The warning does not occur with Scala 2.11.7
Independent of the warning message, I'm heavily interested to know if withFilter
is used? (see question 2 )