Skip to content

Commit

Permalink
Merge pull request #43 from packux/master
Browse files Browse the repository at this point in the history
- added isSuccess/isFailure, as discussed on #42
  • Loading branch information
holograph committed Jun 11, 2015
2 parents 8c49e6b + 77c4e65 commit 5d6f06d
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 5d6f06d

Please sign in to comment.