Oh! Now your other question makes a little more sense. Still not sure what you are doing to create this Unit / Tuple2 mixed list.
This should work:
List((), (), (3,4)).collect { case [email protected] (_: Int, _: Int) => t }.toMap
Note that I use variable binding here (matching binding to t ) to return the same Tuple2 instance that we matched than creating a new one.
Using collect , you convert the type of your list from List[Any] to List[(Int, Int)] , which is required by toMap since it expects some List[(A,B)] .
Note. While this answer should work for you, I still think your design is flawed. You would be better off eliminating a major design flaw rather than treating such symptoms.
It seems like this would be good to use the Scala Option type . In this case, your list of samples will become List(None, None, Some((3,4))) , or you can write it as List(None, None, Some(3->4)) for reading (nested parentheses like this can get confused).
If you use Option , then the type of your list will become List[Option[(Int, Int)]] , which should be much nicer than List[Any] . To get rid of None entries and get the desired List[(Int,Int)] , you can simply call flatten :
List(None, None, Some(3->4)).flatten // res0: List[(Int, Int)] = List((3,4)) List(None, None, Some(3->4)).flatten.toMap // res1: scala.collection.immutable.Map[Int,Int] = Map(3 -> 4)
However, it will be even better if you can not put None entries on your list at all. If you create this list using Scala for understanding, you can use a protector in your expression to remove invalid elements from the output.