Validation

io.github.srs.model.validation.Validation$package.Validation
object Validation

Companion object for Validation that provides utility methods for common validations.

Attributes

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

Members list

Value members

Concrete methods

def bounded[T](field: String, v: T, min: T, max: T, includeMin: Boolean, includeMax: Boolean)(using n: Numeric[T]): Validation[T]

Ensures the given numeric value is within a specified range.

Ensures the given numeric value is within a specified range.

Type parameters

T

the Numeric type.

Value parameters

field

the name of the field being validated.

includeMax

whether the maximum value is inclusive.

includeMin

whether the minimum value is inclusive.

max

the maximum value.

min

the minimum value.

n

the numeric type class instance for the type of v.

v

the numeric value to validate.

Attributes

Returns

Right with the value if it is within the bounds, otherwise Left with a DomainError.OutOfBounds error.

def noCollisions(field: String, elements: Set[Entity]): Validation[Set[Entity]]

Checks if there are no collisions among a set of entities.

Checks if there are no collisions among a set of entities.

Value parameters

elements

the set of entities to check for collisions.

field

the name of the field being validated (for error reporting).

Attributes

Returns

Right with the original set of entities if there are no collisions, otherwise Left with a DomainError.Collision error containing the colliding entities.

def notInfinite[T](field: String, v: T)(using n: Numeric[T]): Validation[T]

Ensures the given numeric value is not infinite.

Ensures the given numeric value is not infinite.

Type parameters

T

the Numeric type.

Value parameters

field

the name of the field being validated.

n

the numeric type class instance for the type of v.

v

the numeric value to validate.

Attributes

Returns

Right with the value if it is not infinite, otherwise Left with a DomainError.Infinite error.

def notNaN[T](field: String, v: T)(using n: Numeric[T]): Validation[T]

Ensures the given numeric value is not NaN (Not a Number).

Ensures the given numeric value is not NaN (Not a Number).

Type parameters

T

the Numeric type.

Value parameters

field

the name of the field being validated.

n

the numeric type class instance for the type of v.

v

the numeric value to validate.

Attributes

Returns

Right with the value if it is not NaN, otherwise Left with a DomainError.NotANumber error.

def positive[T](field: String, v: T)(using n: Numeric[T]): Validation[T]

Ensures the given numeric value is strictly positive.

Ensures the given numeric value is strictly positive.

Type parameters

T

any Numeric type (e.g., Int, Double, etc.)

Value parameters

field

name of the validated field (for error reporting)

v

numeric value to check

Attributes

Returns

Right with the value if it is positive, otherwise Left with a DomainError.NegativeOrZero error.

Example
import io.github.srs.model.validation.Validation.*
positive("width", 10)   // Right(10)
positive("width", 0)    // Left(NegativeOrZero("width", 0.0))
def positiveWithZero[T](field: String, v: T)(using n: Numeric[T]): Validation[T]

Ensures the given numeric value is non-negative, the value can be zero.

Ensures the given numeric value is non-negative, the value can be zero.

Type parameters

T

the Numeric type.

Value parameters

field

the name of the field being validated.

n

the numeric type class instance for the type of v.

v

the numeric value to validate.

Attributes

Returns

Right with the value if it is non-negative, otherwise Left with a DomainError.Negative error.

def validateCountOfType[A : ClassTag](field: String, elements: Seq[_], min: Int, max: Int): Validation[Seq[_]]

Ensures the count of elements of a specific type in a sequence is within a specified range.

Ensures the count of elements of a specific type in a sequence is within a specified range.

Type parameters

A

the type of elements to count (must be a subtype of A).

Value parameters

elements

the sequence of elements to validate.

field

the name of the field being validated.

max

the maximum count of elements of type A (inclusive).

min

the minimum count of elements of type A (inclusive).

Attributes

Returns

Right with the original sequence if the count is within bounds, otherwise Left with a DomainError.InvalidCount error.

def withinBounds(field: String, entities: Set[Entity], width: Int, height: Int): Validation[Set[Entity]]