From 77c4e65ec15a7d3f2e46e858080766775e02aee2 Mon Sep 17 00:00:00 2001 From: panos Date: Thu, 11 Jun 2015 12:59:24 +0200 Subject: [PATCH] - added isSuccess/isFailure, as discussed on https://github.com/wix/accord/issues/42 --- api/src/main/scala/com/wix/accord/Result.scala | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/api/src/main/scala/com/wix/accord/Result.scala b/api/src/main/scala/com/wix/accord/Result.scala index 64e6c0b..696610d 100644 --- a/api/src/main/scala/com/wix/accord/Result.scala +++ b/api/src/main/scala/com/wix/accord/Result.scala @@ -64,6 +64,14 @@ case class GroupViolation( value: Any, constraint: String, description: Option[ * @see [[com.wix.accord.Success]], [[com.wix.accord.Failure]] */ sealed trait Result { + + /** Returns `true` if the `Result` is a `Success`, `false` otherwise. */ + def isSuccess: Boolean + + /** Returns `true` if the `Result` is a `Failure`, `false` otherwise. */ + def isFailure: Boolean + + def and( other: Result ): Result def or( other: Result ): Result @@ -80,6 +88,10 @@ case object Success extends Result { def and( other: Result ) = other def or( other: Result ) = this def withDescription( rewrite: String ) = this + + def isSuccess: Boolean = true + + def isFailure: Boolean = false } /** An object representing a failed validation result. @@ -95,4 +107,8 @@ case class Failure( violations: Set[ Violation ] ) extends Result { case Failure(_) => this } def withDescription( rewrite: String ) = Failure( violations map { _ withDescription rewrite } ) + + def isSuccess: Boolean = false + + def isFailure: Boolean = true }