I’ve written a visitor pattern and I’m matching an overridden subclass. I want to add the variable to the set value of the object and then return the modified object. How can I do that syntactically?
trait PropositionOrderer extends Visitor[Proposition]{
var OurSet = SortedSet[Name] _
override def variable = {
_ match {
case name => Variable(name)//SortedSet+(name).andThen(Variable(_))
}
}
}
Is there syntax to chain like a void function that adds to the SortedSet and then wait? I can’t use andThen because I want to do two things, I want to add it to the Set and then I want to return the variable. Any ideas?
I think you mean something like this:
A
matchexpression will evaluate to the last expression of the matchingcase. Here, thecasethat matches iscase name. The last expression under thecase nameblock isname, so that’s what the entire match evaluates to. So the functionfuncreturnsname, which is"test"when we callfunc("test"). Thus,xis assigned to be“test”`.In addition, you can perform any other operations inside the
caseblock you want. Here, we are modifyingourSet.