All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.neat.internal.RequiredValidator.kt Maven / Gradle / Ivy

There is a newer version: 3.0.13
Show newest version
package neat.internal

import neat.CompoundValidators
import neat.Invalid
import neat.Validator
import neat.Validators
import neat.Validity
import neat.aggregate

@PublishedApi
internal class RequiredValidator

(val validators: Validators

, val message: String) : Validator

{ override val label: String = validators.label override fun validate(value: P?): Validity

= buildList { if (value == null) { add(Invalid(value, listOf(message))) return@buildList } if (validators is CompoundValidators) { addAll( validateRecursively( validators = validators as CompoundValidators, value = value ) ) } else { addAll(validators.functions.values.map { it.function(value) }) } }.aggregate(value) as Validity

}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy