scala> def f[T <: Tuple]: Tuple.Map[Tuple.InverseMap[Tuple.Map[T, Option], Option], Seq] = ???
def f[T <: Tuple]: Tuple.Map[Tuple.InverseMap[Tuple.Map[T, Option], Option], Seq]
Compiler does’t know that this is just Tuple.Map[T, Seq]
, but let’s see if it will work anyway:
scala> def f1: Tuple.Map[(Int, String), Seq] = f[(Int, String)]
def f1: (Seq[Int], Seq[String])
Works as expected. Let’s try generic tuple:
scala> def f2[T <: Tuple]: Tuple.Map[T, Seq] = f[T]
-- [E007] Type Mismatch Error: -------------------------------------------------
1 |def f2[T <: Tuple]: Tuple.Map[T, Seq] = f[T]
| ^^^^
|Found: Tuple.Map[Tuple.InverseMap[Tuple.Map[T, Option], Option], Seq]
|Required: Tuple.Map[T, Seq]
Nope. Let’s try cast:
scala> def f3[T <: Tuple]: Tuple.Map[T, Seq] = f[T].asInstanceOf[Tuple.Map[T, Seq]]
def f3[T <: Tuple]: Tuple.Map[T, Seq]
Works and runs fine (once f
is implemented).
Is there a way to make this work without a cast?