So I want to make sure that the extractor in the case match will give an alias to it the correct generic type, if possible.
trait MyT[A]
case class MyC[A](t: MyT[A])
def foo: MyC[_]
def go[A](t: MyT[A]): Option[MyC[A]] = foo match {
case m@MyC(`t`) => Some(m.copy(t = t))
case _ => None
}
This works but I would prefer to not do the m.copy(t = t). Basically m@ will bind to MyC[Any], but I want it to bind to MyC[A]. Is this possible, maybe with a custom unapply?
m.copy(t = t)will just callMyC(t), so you could write that instead and don't needmhere (which may not apply to your real code, of course). Of course, reusingmwould be better, but this seems to be a strict improvement oncopyto me.MyC, I would need to change the case match as well as the result, whereas copy means I only need to change the case match.A, though.