Validator

com.github.arturopala.validator.Validator
object Validator

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

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Validator.type

Members list

Type members

Classlikes

final case class And extends Error

Sequence of errors resulting from the logical conjunction of constraints.

Sequence of errors resulting from the logical conjunction of constraints.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Error
class Object
trait Matchable
class Any
Show all
final implicit class BigDecimalMatchers(val value: BigDecimal) extends AnyVal

Attributes

Supertypes
class AnyVal
trait Matchable
class Any
final implicit class BooleanOps(val value: Boolean) extends AnyVal

Attributes

Supertypes
class AnyVal
trait Matchable
class Any
object Error

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Error.type
sealed trait Error

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class And
class Or
class Single
final implicit class IntMatchers(val value: Int) extends AnyVal

Attributes

Supertypes
class AnyVal
trait Matchable
class Any
object Invalid

Invalid result helpers.

Invalid result helpers.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Invalid.type
final implicit class OptionalBigDecimalMatchers(val value: Option[BigDecimal]) extends AnyVal

Attributes

Supertypes
class AnyVal
trait Matchable
class Any
final implicit class OptionalIntMatchers(val value: Option[Int]) extends AnyVal

Attributes

Supertypes
class AnyVal
trait Matchable
class Any
final implicit class OptionalStringMatchers(val value: Option[String]) extends AnyVal

Attributes

Supertypes
class AnyVal
trait Matchable
class Any
final case class Or extends Error

Sequence of errors resulting from the logical disjunction of constraints.

Sequence of errors resulting from the logical disjunction of constraints.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Error
class Object
trait Matchable
class Any
Show all
final case class Single extends Error

Single error representation.

Single error representation.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Error
class Object
trait Matchable
class Any
Show all
final implicit class StringMatchers(val value: String) extends AnyVal

Attributes

Supertypes
class AnyVal
trait Matchable
class Any
final implicit class ValidateOps[T](val thisValidate: T => Result)

Attributes

Supertypes
class Object
trait Matchable
class Any
final implicit class ValidationResultOps(val result: Result)

Attributes

Supertypes
class Object
trait Matchable
class Any

Types

type Result = Either[Error, Unit]

Validation result type.

Validation result type.

Attributes

type Validate[-T] = T => Result

The validator function type.

The validator function type.

Attributes

Value members

Concrete methods

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

Conjuction. Succeeds only if all constraints are valid.

Conjuction. Succeeds only if all constraints are valid.

Attributes

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

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

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

Attributes

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

Conjuction. Succeeds only if all constraints are valid, otherwise prepend errorPrefix.

Conjuction. Succeeds only if all constraints are valid, otherwise prepend errorPrefix.

Attributes

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

Conjuction. Succeeds only if all constraints are valid. Breaks the circuit after first invalid result.

Conjuction. Succeeds only if all constraints are valid. Breaks the circuit after first invalid result.

Attributes

def always[T]: () => T

Validator that always succeeds.

Validator that always succeeds.

Attributes

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

Disjunction. Succeeds if any of the constraints is valid.

Disjunction. Succeeds if any of the constraints is valid.

Attributes

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

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

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

Attributes

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

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

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

Attributes

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

Runs all provided checks.

Runs all provided checks.

Attributes

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.

Attributes

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.

Attributes

def checkEachIfNonEmptyWithErrorPrefix[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.

Attributes

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.

Attributes

def checkEachIfSomeWithErrorPrefix[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.

Attributes

def checkEachWithErrorPrefix[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.

Attributes

def checkEither[T, L, R](element: T => Either[L, R], constraintLeft: () => L, constraintRight: () => R): () => T

Apply constraint to the extracted property of type Either[L,R].

Apply constraint to the extracted property of type Either[L,R].

Attributes

def checkEquals[T, A](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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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

Check if all tests fails

Check if all tests fails

Attributes

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.

Attributes

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

Check if all tests passes

Check if all tests passes

Attributes

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.

Attributes

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

Check if at least one test passes.

Check if at least one test passes.

Attributes

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.

Attributes

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

Check if at most one test passes.

Check if at most one test passes.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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

Validate if the test fails, otherwise fail with error.

Validate if the test fails, otherwise fail with error.

Attributes

def checkIsTrue[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.

Attributes

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

Validate if two properties return different value.

Validate if two properties return different value.

Attributes

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

Validate with the provided constraint applied to the extracted property.

Validate with the provided constraint applied to the extracted property.

Attributes

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

Validate with the provided constraint applied to the extracted property.

Validate with the provided constraint applied to the extracted property.

Attributes

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

Validate using the provided implicit constraint applied to the extracted property.

Validate using the provided implicit constraint applied to the extracted property.

Attributes

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.

Attributes

def never[T]: () => T

Validator that always fails.

Validator that always fails.

Attributes

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.

Attributes

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

Combine three constraints to make a constraint on a triplet.

Combine three constraints to make a constraint on a triplet.

Attributes

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.

Attributes

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

Runs all provided checks. Provided as a named alias to the apply method.

Runs all provided checks. Provided as a named alias to the apply method.

Attributes

def validateCollectionNonEmpty(errorMessage: String): () => Iterable[_]
def validateStringNonEmpty(errorMessage: String): () => String
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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

Concrete fields

val Valid: Right[Nothing, Unit]

Successsful validation result alias.

Successsful validation result alias.

Attributes

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 def OptionalBigDecimalMatchers(value: Option[BigDecimal]): OptionalBigDecimalMatchers
final implicit def OptionalIntMatchers(value: Option[Int]): OptionalIntMatchers
final implicit def OptionalStringMatchers(value: Option[String]): OptionalStringMatchers
final implicit def StringMatchers(value: String): StringMatchers
final implicit def ValidateOps[T](thisValidate: T => Result): ValidateOps[T]
final implicit def ValidationResultOps(result: Result): ValidationResultOps