I’m trying to pattern match on a Scala list with a pattern that will match if an object of the desired type is contained anywhere within the list.
I tried:
case _ :: (something: DesiredSubclass) :: _ => ???
But this only matches if there is at least one element before the one that I’m looking for.
Use of overt
isInstanceOf[SomeType]is unsightly. Using thematch-likePartialFunctionliteral notation is preferable: