Assume you have a List(1,"1") it is typed List[Any], which is of course correct and expected. Now if I map the list like this
scala> List(1, "1") map {
| case x: Int => x
| case y: String => y.toInt
| }
the resulting type is List[Int] which is expected as well. My question is if there is an equivalent to map for filter because the following example will result in a List[Any]. Is this possible? I assume this could be solved at compile time and possibly not runtime?
scala> List(1, "1") filter {
| case x: Int => true
| case _ => false
| }