title: How to implement simple validation in Scala
body: <p>Suppose I need to validate request parameters. The validation result is either <code>Success</code> or <code>Failure</code> with <code>NonEmptyList[String]</code>. I can probably use <code>ValidationNel[String, Unit]</code> but it seems a bit overkill. I guess I need a <em>simpler</em> abstraction (see below). </p>
  
  <pre><code>trait ValidationResult
  object Success extends ValidationResult
  class Failure(errors: NonEmptyList[String]) extends ValidationResult
  </code></pre>
  
  <p>and a binary operation <code>andAlso</code> to combine two results:</p>
  
  <pre><code>trait ValidationResult {
    def andAlso(other: ValidationResult): ValidationResult = 
      (this, other) match {
        case (Success, Success) =&gt; Success
        case (Success, failure @ Failure(_)) =&gt; failure
        case (failure @ Failure(_), Success) =&gt; failure
        case (Failure(errors1), Failure(errors2)) =&gt; Failure(errors1 + errors2) 
      } 
  }
  </code></pre>
  
  <p>Now if I validate three parameters with functions <code>checkA</code>, <code>checkB</code>, and <code>checkC</code> I can easily compose them as follows:</p>
  
  <pre><code>def checkA(a: A): ValidationResult = ...
  def checkB(b: B): ValidationResult = ...
  def checkC(c: C): ValidationResult = ...
  def checkABC(a: A, b: B, c: C) = checkA(a) andAlso checkB(b) andAlso checkC(c)
  </code></pre>
  
  <p>Does it make sense ?<br>
  Does this abstraction have a name ? Maybe a <code>Monoid</code> ?<br>
  Is it implemented in <code>scalaz</code> or any other scala library ?</p>