You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In your example, you would need to return something in the else block. If you wanted to reduce nesting, you could move the permission check into the pattern match, i.e.
defindex():Action[AnyContent] =Action.async { implicitrq: Request[AnyContent] =>
rq.getQueryString("permission-field") match {
caseSome(pf) if (!permissioned.contains(pf)) =>Action(Forbidden)
caseSome(pf) =>// do other stuffcaseNone=>Future { BadRequest }
}
}
Besides, return is anti structural programming, as functions can be described with multiple exit points and if you need return, like in those gigantic methods with lots of if/else branches, the presence of a return is a clear signal that the code stinks, a magnet for future bugs and is thus in urgent need of refactoring.
One question I had was what if you explicitly want control flow to return to the calling function?
For example, in a web controller function I have the following:
The text was updated successfully, but these errors were encountered: