I'm trying to get the minimum and maximum values in a list of ordered numbers. There is no problem when working with specific type:
private def minMaxValue (valuesList: List[Option[Int]], min: Boolean): Option[Int] =
valuesList.flatten match {
case Nil => None
case xs => Some(if (min) xs.min else xs.max)
}
but when I can't find the way to change it to also accept Long and Float, I tried:
private def minMaxValue (valuesList: List[Option[Any]], min: Boolean): Option[Int] =
valuesList.flatten match {
case Nil => None
case xs: List[Int] => Some(if (min) xs.min else xs.max)
case xs: List[Long] => Some(if (min) xs.min else xs.max)
}
but it doesn't work and I get this warning for
- non-variable type argument Int in type pattern List[Int] (the underlying of List[Int]) is unchecked since it is eliminated by erasure
What is the best way to solve this in scala?