I have the following toy function:
def test[T](x: Option[List[Option[T]]])
{
for (a <- x; b <- a; c <- b) println(c)
println("----------")
}
How can I generalize the above function so it also works with Option[Option[Option[T]]] or List[List[List[T]]] or any other combination of Option and List?
The following attempt obviously doesn’t work, because types aren’t type constructors:
def test2[Q,R,S,T](x: Q[R[S[T]]])
In C++, I would probably use template templates for this purpose. Does Scala have something like that?
Can you use Scalaz? If so this is pretty easy with the
Eachtype class: