if
condition as case's entry guard SC-R1023When pattern matching, case
s allow you to specify conditions that act as entry guards. Controller then enters into the body of these case
s only if these conditions satisfy. In scenarios where the body of a case
is wrapped in an if
condition, consider moving this if
condition and rewriting it as an entry guard. Doing so improves the overall readability of the code.
Users.getDetails(emailId) match {
case Some(details) =>
if (details.isAdmin) {
// ...
}
case None =>
}
Users.getDetails(emailId) match {
case Some(details) if details.isAdmin =>
// ...
case None =>
}