object Validator
Simpler validator abstraction using Cats Validated https://typelevel.org/cats/datatypes/validated.html.
- Alphabetic
- By Inheritance
- Validator
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- final case class And extends Error with Product with Serializable
Sequence of errors resulting from the logical conjunction of constraints.
- implicit final class BigDecimalMatchers extends AnyVal
- implicit final class BooleanOps extends AnyVal
- sealed trait Error extends AnyRef
- implicit final class IntMatchers extends AnyVal
- implicit final class OptionalBigDecimalMatchers extends AnyVal
- implicit final class OptionalIntMatchers extends AnyVal
- implicit final class OptionalStringMatchers extends AnyVal
- final case class Or extends Error with Product with Serializable
Sequence of errors resulting from the logical disjunction of constraints.
- type Result = Either[Error, Unit]
Validation result type.
- final case class Single extends Error with Product with Serializable
Single error representation.
- implicit final class StringMatchers extends AnyVal
- type Validate[-T] = (T) => Result
The validator function type.
- implicit final class ValidateOps[T] extends AnyRef
- implicit final class ValidationResultOps extends AnyRef
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- val Valid: Right[Nothing, Unit]
Successsful validation result alias.
- def all[T](constraints: Validate[T]*): Validate[T]
Conjuction.
Conjuction. Succeeds only if all constraints are valid.
- def allWithComputedPrefix[T](errorPrefix: (T) => String, constraints: Validate[T]*): Validate[T]
Conjuction.
Conjuction. Succeeds only if all constraints are valid, otherwise prepend calculated errorPrefix.
- def allWithPrefix[T](errorPrefix: String, constraints: Validate[T]*): Validate[T]
Conjuction.
Conjuction. Succeeds only if all constraints are valid, otherwise prepend errorPrefix.
- def allWithShortCircuit[T](constraints: Validate[T]*): Validate[T]
Conjuction.
Conjuction. Succeeds only if all constraints are valid. Breaks the circuit after first invalid result.
- def always[T]: Validate[T]
Validator that always succeeds.
- def any[T](constraints: Validate[T]*): Validate[T]
Disjunction.
Disjunction. Succeeds if any of the constraints is valid.
- def anyWithComputedPrefix[T](errorPrefix: (T) => String, constraints: Validate[T]*): Validate[T]
Disjunction.
Disjunction. Succeeds if any of the constraints is valid, otherwise prepend errorPrefix.
- def anyWithPrefix[T](errorPrefix: String, constraints: Validate[T]*): Validate[T]
Disjunction.
Disjunction. Succeeds if any of the constraints is valid, otherwise prepend errorPrefix.
- def apply[T](constraints: Validate[T]*): Validate[T]
Runs all provided checks.
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def checkEach[T, E](elements: (T) => Seq[E], constraint: Validate[E]): Validate[T]
Apply constraint to each element of the extracted sequence.
- def checkEachIfNonEmpty[T, E](elements: (T) => Seq[E], constraint: Validate[E]): Validate[T]
Apply constraint to each element of the extracted sequence if non empty.
- def checkEachIfNonEmptyWithErrorPrefix[T, E](elements: (T) => Seq[E], constraint: Validate[E], errorPrefix: (Int) => String): Validate[T]
Apply constraint to each element of the extracted sequence if non empty.
Apply constraint to each element of the extracted sequence if non empty. If invalid then compute and add prefix to the errors.
- def checkEachIfSome[T, E](extract: (T) => Option[Seq[E]], constraint: Validate[E], isValidIfNone: Boolean = true): Validate[T]
Apply constraint to each element of the extracted sequence if defined.
- def checkEachIfSomeWithErrorPrefix[T, E](extract: (T) => Option[Seq[E]], constraint: Validate[E], errorPrefix: (Int) => String, isValidIfNone: Boolean): Validate[T]
Apply constraint to each element of the extracted sequence if non empty.
Apply constraint to each element of the extracted sequence if non empty. If invalid then compute and add prefix to the errors.
- def checkEachWithErrorPrefix[T, E](elements: (T) => Seq[E], constraint: Validate[E], errorPrefix: (Int) => String): Validate[T]
Apply constraint to each element of the extracted sequence.
Apply constraint to each element of the extracted sequence. If invalid then compute and add prefix to the errors.
- def checkEither[T, L, R](element: (T) => Either[L, R], constraintLeft: Validate[L], constraintRight: Validate[R]): Validate[T]
Apply constraint to the extracted property of type Either[L,R].
- def checkEquals[T, A](value1: (T) => A, value2: (T) => A, error: String): Validate[T]
Validate if two properties return the same value.
- def checkFromEither[T](test: (T) => Either[String, Any]): Validate[T]
Validate if the test returns Right, otherwise fail with Left error.
- def checkIfAllDefined[T](extractors: Seq[(T) => Option[Any]], expectations: String): Validate[T]
Check if all extracted optional properties are defined.
- def checkIfAllEmpty[T](extractors: Seq[(T) => Option[Any]], expectations: String): Validate[T]
Check if all extracted optional properties are empty.
- def checkIfAllFalse[T](tests: Seq[(T) => Boolean], expectations: String): Validate[T]
Check if all tests fails
- def checkIfAllOrNoneDefined[T](extractors: Seq[(T) => Option[Any]], expectations: String): Validate[T]
Check if the extracted optional properties are either all defined or all empty.
- def checkIfAllTrue[T](tests: Seq[(T) => Boolean], expectations: String): Validate[T]
Check if all tests passes
- def checkIfAtLeastOneIsDefined[T](extractors: Seq[(T) => Option[Any]], expectations: String): Validate[T]
Check if at least one extracted property is defined.
- def checkIfAtLeastOneIsTrue[T](tests: Seq[(T) => Boolean], expectations: String): Validate[T]
Check if at least one test passes.
- def checkIfAtMostOneIsDefined[T](extractors: Seq[(T) => Option[Any]], expectations: String): Validate[T]
Check if at most one extracted property is defined.
- def checkIfAtMostOneIsTrue[T](tests: Seq[(T) => Boolean], expectations: String): Validate[T]
Check if at most one test passes.
- def checkIfOnlyOneIsDefined[T](extractors: Seq[(T) => Option[Any]], expectations: String): Validate[T]
Check if one and only one extracted property is defined.
- def checkIfOnlyOneIsTrue[T](tests: Seq[(T) => Boolean], expectations: String): Validate[T]
Check if one and only one test passes.
- def checkIfOnlyOneSetIsDefined[T](extractors: Seq[Set[(T) => Option[Any]]], expectations: String): Validate[T]
Check if one and only one set of properties is fully defined.
- def checkIfOnlyOneSetIsTrue[T](tests: Seq[Set[(T) => Boolean]], expectations: String): Validate[T]
Check if one and only one set of tests passes.
- def checkIfSome[T, E](element: (T) => Option[E], constraint: Validate[E], isValidIfNone: Boolean = true): Validate[T]
Apply constraint to the extracted property if defined, otherwise follow isValidIfNone flag.
- def checkIsDefined[T](test: (T) => Option[Any], error: String): Validate[T]
Validate if the test returns Some, otherwise fail with error.
- def checkIsEmpty[T](test: (T) => Option[Any], error: String): Validate[T]
Validate if the test returns None, otherwise fail with error.
- def checkIsFalse[T](test: (T) => Boolean, error: String): Validate[T]
Validate if the test fails, otherwise fail with error.
- def checkIsTrue[T](test: (T) => Boolean, error: String): Validate[T]
Validate if the test passes, otherwise fail with error.
- def checkNotEquals[T, A](value1: (T) => A, value2: (T) => A, error: String): Validate[T]
Validate if two properties return different value.
- def checkProp[T, E](element: (T) => E, constraint: Validate[E]): Validate[T]
Validate with the provided constraint applied to the extracted property.
- def checkWith[T, E](element: (T) => E, constraint: Validate[E]): Validate[T]
Validate with the provided constraint applied to the extracted property.
- def checkWithImplicitly[T, E](element: (T) => E)(implicit constraint: Validate[E]): Validate[T]
Validate using the provided implicit constraint applied to the extracted property.
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def conditionally[T](test: (T) => Boolean, constraintWhenTrue: Validate[T], constraintWhenFalse: Validate[T]): Validate[T]
Depending on the test result follow continue with either first or second constraint.
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def never[T]: Validate[T]
Validator that always fails.
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def product[A, B, C, D](constraintA: Validate[A], constraintB: Validate[B], constraintC: Validate[C], constraintD: Validate[D]): Validate[(A, B, C, D)]
Combine four constraints to make a constraint on a tuple.
- def product[A, B, C](constraintA: Validate[A], constraintB: Validate[B], constraintC: Validate[C]): Validate[(A, B, C)]
Combine three constraints to make a constraint on a triplet.
- def product[A, B](constraintA: Validate[A], constraintB: Validate[B]): Validate[(A, B)]
Combine two constraints to make a constraint on a pair.
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def validate[T](constraints: Validate[T]*): Validate[T]
Runs all provided checks.
Runs all provided checks. Provided as a named alias to the apply method.
- def validateCollectionNonEmpty(errorMessage: String): (Iterable[_]) => Result
- def validateStringNonEmpty(errorMessage: String): Validate[String]
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- def when[T](guardConstraint: Validate[T], constraintWhenValid: Validate[T], constraintWhenInvalid: Validate[T]): Validate[T]
Depending on the guard constraint result continue with either first or second constraint.
- def whenFalse[T](test: (T) => Boolean, constraintWhenFalse: Validate[T]): Validate[T]
If the test is false then try the next constraint, otherwise valid.
- def whenInvalid[T](guardConstraint: Validate[T], constraintWhenInvalid: Validate[T]): Validate[T]
If the guard constraint is invalid then try next constraint.
- def whenTrue[T](test: (T) => Boolean, constraintWhenTrue: Validate[T]): Validate[T]
If the test is true then check the next constraint, otherwise valid.
- def whenValid[T](guardConstraint: Validate[T], constraintWhenValid: Validate[T]): Validate[T]
If the guard constraint is valid then check next constraint.
- object Error
- object Invalid
Invalid result helpers.