commonMain.neat.internal.OptionalValidator.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neat-validation-jvm Show documentation
Show all versions of neat-validation-jvm Show documentation
A collection library that is built with interoperability in mind
package neat.internal
import neat.CompoundValidators
import neat.Valid
import neat.Validator
import neat.Validators
import neat.Validity
import neat.aggregate
@PublishedApi
internal class OptionalValidator(val validators: Validators
) : Validator
{
override val label: String = validators.label
override fun validate(value: P?): Validity
{
if (value == null) return Valid(value)
if (validators is CompoundValidators) {
return validateRecursively(
validators = validators as CompoundValidators,
value = value
).aggregate(value)
}
return validators.functions.values.map {
it.function(value)
}.aggregate(value)
}
}