I have the following case class:
case class MyClass[A,B](a:A, b:B)
I want to add a function like unzip to MyClass
so if A
and B
are Tuple types then I want to extract them like the following:
val item = MyClass[(Int,String), (Int,String)]((2,"two"), (3,"three"))
val item_left = MyClass(item.a._1, item.b._1)
val item_right = MyClass(item.a._2, item.b._2)
How should I do that and check the type for tuple in compile time? I don't want to define it in the companion object and I want it to be a function in MyClass
. I know that I can define an implicit
function but is it the only way?