I am playing with generics and upper bounds in scala and I am facing the following problem:
Let's say I have the following function (where I only expect either Int or Char):
def foo[T](tuple: Tuple2[T, T]) = tuple match {
case Tuple2(x: Int, y: Int) => (x to y).toArray
case Tuple2(x: Char, y: Char) => (x to y).toArray
}
I would expect to have a better and compressed form like:
def foo2[T >: Int with Char <: AnyVal](tuple: (T, T)) = (tuple._1 to tuple._2).toArray
But this is definitely not working.
Any ideas?