I wrote a code the other day to filter out mixing behavior form a list.
Her is an example code which should describe the problem I ran into.
def myFilter[A](toFilter : Any) : Option[A] = toFilter match {
case keep : A => Some(keep)
case _ => None
}
// what happens
myFilter[Int]("hallo") // => Option[Int] = Some(hallo)
// what I expect
myFilter[Int]("hallo") // => Option[Int] = None
myFilter[Int](1) // => Option[Int] = Some(1)
Maybe I'm doing something completely wrong, but it created a lot of problems on my side, I have to create a lot of code now, which I was hoping to make more readable by this function.