Validator

object Validator

Simpler validator abstraction using Cats Validated https://typelevel.org/cats/datatypes/validated.html.

class Object
trait Matchable
class Any

Type members

Classlikes

final implicit
class BigDecimalMatchers(val value: BigDecimal) extends AnyVal
final implicit
class BooleanOps(val value: Boolean) extends AnyVal
object Implicits
final implicit
class IntMatchers(val value: Int) extends AnyVal
final implicit
class OptionalBigDecimalMatchers(val value: Option[BigDecimal]) extends AnyVal
final implicit
class OptionalIntMatchers(val value: Option[Int]) extends AnyVal
final implicit
class OptionalStringMatchers(val value: Option[String]) extends AnyVal
final implicit
class StringMatchers(val value: String) extends AnyVal
final implicit
class ValidateOps[T](val thisValidate: T => Validated[List[String], Unit])
final implicit
class ValidatedOps(val validated: Validated[List[String], Unit])

Types

final
type Validate[T] = T => Validated[List[String], Unit]

The validator function.

The validator function.

Value members

Concrete methods

def all[T](constraints: () => T*): () => T

Succeed only if all constraints are valid.

Succeed only if all constraints are valid.

def allWithComputedPrefix[T](errorPrefix: T => String, constraints: () => T*): () => T

Succeed only if all constraints are valid, otherwise prepend calculated errorPrefix.

Succeed only if all constraints are valid, otherwise prepend calculated errorPrefix.

def allWithPrefix[T](errorPrefix: String, constraints: () => T*): () => T

Succeed only if all constraints are valid, otherwise prepend errorPrefix.

Succeed only if all constraints are valid, otherwise prepend errorPrefix.

def always[T]: () => T
def any[T](constraints: () => T*): () => T

Succeed if any of the constraints is valid.

Succeed if any of the constraints is valid.

def anyWithComputedPrefix[T](errorPrefix: T => String, constraints: () => T*): () => T

Succeed if any of the constraints is valid, otherwise prepend errorPrefix.

Succeed if any of the constraints is valid, otherwise prepend errorPrefix.

def anyWithPrefix[T](errorPrefix: String, constraints: () => T*): () => T

Succeed if any of the constraints is valid, otherwise prepend errorPrefix.

Succeed if any of the constraints is valid, otherwise prepend errorPrefix.

def apply[T](constraints: () => T*): () => T

Combine provided validator functions.

Combine provided validator functions.

def check[T](test: T => Boolean, error: String): () => T

Validate if the test passes, otherwise fail with error.

Validate if the test passes, otherwise fail with error.

def checkEach[T, E](elements: T => Seq[E], constraint: () => E): () => T

Apply constraint to each element of the extracted sequence.

Apply constraint to each element of the extracted sequence.

def checkEach[T, E](elements: T => Seq[E], constraint: () => E, errorPrefix: Int => String): () => T

Apply constraint to each element of the extracted sequence. If invalid then compute and add prefix to the errors.

Apply constraint to each element of the extracted sequence. If invalid then compute and add prefix to the errors.

def checkEachIfNonEmpty[T, E](elements: T => Seq[E], constraint: () => E): () => 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.

def checkEachIfNonEmpty[T, E](elements: T => Seq[E], constraint: () => E, errorPrefix: Int => String): () => T

Apply constraint to each element of the extracted sequence if non empty. If invalid then compute and add prefix to the errors.

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: () => E, isValidIfNone: Boolean): () => T

Apply constraint to each element of the extracted sequence if defined.

Apply constraint to each element of the extracted sequence if defined.

def checkEachIfSome[T, E](extract: T => Option[Seq[E]], constraint: () => E, errorPrefix: Int => String, isValidIfNone: Boolean): () => T

Apply constraint to each element of the extracted sequence if non empty. If invalid then compute and add prefix to the errors.

Apply constraint to each element of the extracted sequence if non empty. If invalid then compute and add prefix to the errors.

def checkEquals[T, A : Eq](value1: T => A, value2: T => A, error: String): () => T

Validate if two properties return the same value.

Validate if two properties return the same value.

def checkFromEither[T](test: T => Either[String, Any]): () => T

Validate if the test returns Right, otherwise fail with Left error.

Validate if the test returns Right, otherwise fail with Left error.

def checkFromEither[T](test: T => Either[String, Any], errorPrefix: String): () => T

Validate if the test returns Right, otherwise fail with Left error prefixed.

Validate if the test returns Right, otherwise fail with Left error prefixed.

def checkIfAllDefined[T](extractors: Seq[T => Option[Any]], expectations: String): () => T

Check if all extracted optional properties are defined.

Check if all extracted optional properties are defined.

def checkIfAllEmpty[T](extractors: Seq[T => Option[Any]], expectations: String): () => T

Check if all extracted optional properties are empty.

Check if all extracted optional properties are empty.

def checkIfAllOrNoneDefined[T](extractors: Seq[T => Option[Any]], expectations: String): () => T

Check if the extracted optional properties are either all defined or all empty.

Check if the extracted optional properties are either all defined or all empty.

def checkIfAllTrue[T](tests: Seq[T => Boolean], expectations: String): () => T

Check if all tests passes

Check if all tests passes

def checkIfAtLeastOneIsDefined[T](extractors: Seq[T => Option[Any]], expectations: String): () => T

Check if at least one extracted property is defined.

Check if at least one extracted property is defined.

def checkIfAtLeastOneIsTrue[T](tests: Seq[T => Boolean], expectations: String): () => T

Check if at least one test passes.

Check if at least one test passes.

def checkIfAtMostOneIsDefined[T](extractors: Seq[T => Option[Any]], expectations: String): () => T

Check if at most one extracted property is defined.

Check if at most one extracted property is defined.

def checkIfAtMostOneIsTrue[T](tests: Seq[T => Boolean], expectations: String): () => T

Check if at most one test passes.

Check if at most one test passes.

def checkIfOnlyOneIsDefined[T](extractors: Seq[T => Option[Any]], expectations: String): () => T

Check if one and only one extracted property is defined.

Check if one and only one extracted property is defined.

def checkIfOnlyOneIsTrue[T](tests: Seq[T => Boolean], expectations: String): () => T

Check if one and only one test passes.

Check if one and only one test passes.

def checkIfOnlyOneSetIsDefined[T](extractors: Seq[Set[T => Option[Any]]], expectations: String): () => T

Check if one and only one set of properties is fully defined.

Check if one and only one set of properties is fully defined.

def checkIfOnlyOneSetIsTrue[T](tests: Seq[Set[T => Boolean]], expectations: String): () => T

Check if one and only one set of tests passes.

Check if one and only one set of tests passes.

def checkIfSome[T, E](element: T => Option[E], constraint: () => E, isValidIfNone: Boolean): () => T

Apply constraint to the extracted property if defined, otherwise follow isValidIfNone flag.

Apply constraint to the extracted property if defined, otherwise follow isValidIfNone flag.

def checkIfSome[T, E](element: T => Option[E], validator: () => E, errorPrefix: String, isValidIfNone: Boolean): () => T

Apply constraint to the extracted property if defined, otherwise follow isValidIfNone flag. If invalid then add prefix to the errors.

Apply constraint to the extracted property if defined, otherwise follow isValidIfNone flag. If invalid then add prefix to the errors.

def checkIsDefined[T](test: T => Option[Any], error: String): () => T

Validate if the test returns Some, otherwise fail with error.

Validate if the test returns Some, otherwise fail with error.

def checkIsEmpty[T](test: T => Option[Any], error: String): () => T

Validate if the test returns None, otherwise fail with error.

Validate if the test returns None, otherwise fail with error.

def checkNotEquals[T, A : Eq](value1: T => A, value2: T => A, error: String): () => T

Validate if two properties return different value.

Validate if two properties return different value.

def checkProperty[T, E](element: T => E, constraint: () => E): () => T

Apply constraint to the extracted property.

Apply constraint to the extracted property.

def checkProperty[T, E](element: T => E, constraint: () => E, errorPrefix: String): () => T

Apply constraint to the extracted property and if invalid then add prefix to the errors.

Apply constraint to the extracted property and if invalid then add prefix to the errors.

def conditionally[T](test: T => Boolean, constraintWhenTrue: () => T, constraintWhenFalse: () => T): () => T

Depending on the test result follow continue with either first or second constraint.

Depending on the test result follow continue with either first or second constraint.

def never[T]: () => T
def product[A, B](constraintA: () => A, constraintB: () => B): () => (A, B)

Combine two constraints to make a constraint on a pair.

Combine two constraints to make a constraint on a pair.

def product[A, B, C](constraintA: () => A, constraintB: () => B, constraintC: () => C): () => (A, B, C)

Combine three constraints to make a constraint on a tuple.

Combine three constraints to make a constraint on a tuple.

def product[A, B, C, D](constraintA: () => A, constraintB: () => B, constraintC: () => C, constraintD: () => D): () => (A, B, C, D)

Combine four constraints to make a constraint on a tuple.

Combine four constraints to make a constraint on a tuple.

def validate[T](constraints: T => Validated[String, Unit]*): () => T
def when[T](guardConstraint: () => T, constraintWhenValid: () => T, constraintWhenInvalid: () => T): () => T

Depending on the guard constraint result continue with either first or second constraint.

Depending on the guard constraint result continue with either first or second constraint.

def whenFalse[T](test: T => Boolean, constraintWhenFalse: () => T): () => T

If the test is false then try the next constraint, otherwise valid.

If the test is false then try the next constraint, otherwise valid.

def whenInvalid[T](guardConstraint: () => T, constraintWhenInvalid: () => T): () => T

If the guard constraint is invalid then try next constraint.

If the guard constraint is invalid then try next constraint.

def whenTrue[T](test: T => Boolean, constraintWhenTrue: () => T): () => T

If the test is true then check the next constraint, otherwise valid.

If the test is true then check the next constraint, otherwise valid.

def whenValid[T](guardConstraint: () => T, constraintWhenValid: () => T): () => T

If the guard constraint is valid then check next constraint.

If the guard constraint is valid then check next constraint.

Implicits

Implicits

final implicit
def BigDecimalMatchers(value: BigDecimal): BigDecimalMatchers
final implicit
def BooleanOps(value: Boolean): BooleanOps
final implicit
def IntMatchers(value: Int): IntMatchers
final implicit
final implicit
def OptionalIntMatchers(value: Option[Int]): OptionalIntMatchers
final implicit
final implicit
def StringMatchers(value: String): StringMatchers
final implicit
def ValidateOps[T](thisValidate: T => Validated[List[String], Unit]): ValidateOps[T]
final implicit
def ValidatedOps(validated: Validated[List[String], Unit]): ValidatedOps