
octopus.syntax.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of octopus_sjs0.6_2.12 Show documentation
Show all versions of octopus_sjs0.6_2.12 Show documentation
Boilerplate-free validation library for Scala
The newest version!
package octopus
import scala.language.higherKinds
object syntax {
implicit class ValidationOps[T](val obj: T) extends AnyVal with Serializable {
def validate(implicit v: Validator[T]): ValidationResult[T] =
new ValidationResult(obj, v.validate(obj))
def isValid(implicit v: Validator[T]): Boolean =
validate.isValid
}
implicit class AsyncValidationOps[T](val obj: T) extends AnyVal with Serializable {
def validateAsync[M[_]](implicit av: AsyncValidatorM[M, T], appError: AppError[M]): M[ValidationResult[T]] =
appError.map(av.validate(obj)) { errors =>
new ValidationResult(obj, errors)
}
def isValidAsync[M[_]](implicit av: AsyncValidatorM[M, T], appError: AppError[M]): M[Boolean] =
appError.map(validateAsync)(_.isValid)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy