Validierung von Methodenparametern in Scala, zum Verständnis und für Monaden

Ich versuche die Parameter einer Methode auf Null zu überprüfen, aber ich finde keine Lösung ...

Kann mir jemand sagen, wie es geht?

Ich versuche so etwas:

  def buildNormalCategory(user: User, parent: Category, name: String, description: String): Either[Error,Category] = {
    val errors: Option[String] = for {
      _ <- Option(user).toRight("User is mandatory for a normal category").right
      _ <- Option(parent).toRight("Parent category is mandatory for a normal category").right
      _ <- Option(name).toRight("Name is mandatory for a normal category").right
      errors : Option[String] <- Option(description).toRight("Description is mandatory for a normal category").left.toOption
    } yield errors
    errors match {
      case Some(errorString) => Left( Error(Error.FORBIDDEN,errorString) )
      case None =>  Right( buildTrashCategory(user) )
    }
  }

Antworten auf die Frage(4)

Ihre Antwort auf die Frage