Skip to content

Commit

Permalink
- added isSuccess/isFailure, as discussed on wix-incubator#42
Browse files Browse the repository at this point in the history
  • Loading branch information
panosAthDBX committed Jun 11, 2015
1 parent 8c49e6b commit 77c4e65
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions api/src/main/scala/com/wix/accord/Result.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand All @@ -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
}

0 comments on commit 77c4e65

Please sign in to comment.