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

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9

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
}


Got any Scala Language Question?