score:0

Accepted answer

You could create your own unapply method like this:

object CVEquality {
  def unapply(e: Equality): Option(String, String) = e match {
    case Equality(Variable(v), Constructor(c)) => Some(c -> v)
    case Equality(Constructor(c), Variable(v)) => Some(c -> v)
    case _ => None
  }
}

Usage:

def foobar(e:Equality) = e match {
    case CVEquality(c, v) => "do something rather complicated with c and v"
}

The easiest way is to create method for something rather complicated:

def complicated(c: String, v: String) = "do something rather complicated with c and v"

def foobar(e:Equality) = e match {
    case Equality(Variable(x),Constructor(y)) => complicated(y, x)
    case Equality(Constructor(y),Variable(x)) => complicated(y, x)
}

Related Query

More Query from same tag