Validation
Companion object for Validation that provides utility methods for common validations.
Attributes
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Validation.type
Members list
Value members
Concrete methods
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.
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.
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.
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.
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))
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.
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.