Scala Language Don't pack too much in one expression.


Example

  • Find meaningful names for computation units.
  • Use for comprehensions or map to combine computations together.

Let's say you have something like this:

if (userAuthorized.nonEmtpy) {
  makeRequest().map {
    case Success(respone) =>
      someProcessing(..)
      if (resendToUser) {
        sendToUser(...)
      }
    ...
  }
}

If all your functions return Either or another Validation-like type, you can write:

for {
  user     <- authorizeUser
  response <- requestToThirdParty(user)
  _        <- someProcessing(...)
} {
  sendToUser
}