I have a function that returns some preferences, but first I have to do some checks to see whether the user is authorised to read them. I'm still not happy with the result (the match is a bit ugly).
Note: Result
is a framework class, it just means some kind of response.
// implementations are not relevant.
def canAccessPreferences(id: Long): Future[Boolean] = ???
def doGetPreferences(id: Long): Future[Result] = ???
def getPreferences(id: Long) = Future[Result] {
canAccessPreferences(id).flatMap {
case false =>
Future.successful(Forbidden)
case true =>
doGetPreferences(id)
}
}