I am trying to process a tuple, where one of the cases is that the two values are equal. Is there a better, more concise way to match on this than
(p, q) match {
case (p, q) if (p == q) => println("Match!")
...
}
?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Personally, I think the way you’ve done it is great because it’s simple, intuitive, and clear to the reader what’s going on.
That said, here’s one way you could do it without an
ifclause. You could just match on the swapped version, using backticks to turnqinto stable identifiers. As @Luigi pointed out, you can just check thatpmatchesq:Like this: