I have a case class, for example:
I want to combine:
var n : Exp = ... n match { ... case e @ A (a, b) => foo(e, a) foo(e, b) case e @ B (a, b) => foo(e, a) foo(e, b) case e @ C (a, b) => foo(e, a) foo(e, b) ... } def foo(e : Exp, abc : Exp) { ... }
Is there a way to combine these three cases into one case (without adding an intermediate parent class to A, B, C)? I cannot change the definition of A, B, C or Exp. Something like:
var n : Exp = ... n match { ... case e @ (A | B | C) (a, b) =>
which obviously does not work, and do not:
var n : Exp = ... n match { ... case e @ (A (a, b) | B (a, b) | C (a, b)) =>
scala pattern-matching case-class
Lie ryan
source share