Last active
April 11, 2018 07:07
-
-
Save afsalthaj/91a8ef615cb5dade829bf326e8e7bb9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz.ValidationNel | |
trait Validation[A] { | |
def validate(a: A): ValidationNel[ValidationError, A] | |
} | |
object Validation { | |
implicit def validation[A](implicit a: Validation[A]): Validation[A] = a | |
// Inspired from shapeless docs | |
def createInstance[A](f: A => ValidationNel[ValidationError, A]): Validation[A] = { | |
a => f(a) | |
} | |
implicit class Validator[A](a: A) { | |
def validate(implicit validator: Validation[A]): ValidationNel[ValidationError, A] = | |
validator validate a | |
} | |
sealed trait ValidationError | |
object ValidationError { | |
case class InvalidValue(msg: String) extends ValidationError | |
// Bla | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment