Funx.Validator.GreaterThan (funx v0.8.0)
View SourceValidates that a value is strictly greater than a given reference value
using an Ord comparator.
GreaterThan enforces an ordering constraint of the form:
"value must be greater than X".
Ordering is defined by an Ord instance, not by numeric comparison or
structural operators.
Options
:value(required) The reference value to compare against.:ord(optional) An ordering comparator. Defaults toFunx.Ord.Protocol.:message(optional) A custom error message callback(value -> String.t())used to override the default error message on failure.
Semantics
- If the value compares as
:gtrelative to the reference value under the givenOrd, validation succeeds. - If the value compares as
:ltor:eq, validation fails. Nothingvalues are preserved and treated as not applicable.Justvalues are unwrapped before comparison.
Examples
iex> Funx.Validator.GreaterThan.validate(7, value: 5)
%Funx.Monad.Either.Right{right: 7}
iex> Funx.Validator.GreaterThan.validate("b", value: "a")
%Funx.Monad.Either.Right{right: "b"}
iex> Funx.Validator.GreaterThan.validate("a", value: "a")
%Funx.Monad.Either.Left{
left: %Funx.Errors.ValidationError{
errors: ["must be greater than \"a\""]
}
}
iex> Funx.Validator.GreaterThan.validate(%Funx.Monad.Maybe.Nothing{}, value: 5)
%Funx.Monad.Either.Right{right: %Funx.Monad.Maybe.Nothing{}}