commonMain.ru.astrainteractive.klibs.mikro.validation.DefaultValidator.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mikro-validation Show documentation
Show all versions of mikro-validation Show documentation
Kotlin Multiplatform library with useful code
The newest version!
package ru.astrainteractive.klibs.mikro.validation
import ru.astrainteractive.klibs.mikro.validation.impl.ValidationContextImpl
class DefaultValidator(
private val context: ValidationContext.() -> Unit
) : Validator {
override fun validate(value: T): ValidatorResult {
val validationContext = ValidationContextImpl(value).apply(context)
val validators = validationContext.create()
return validators
.map { it.validate(value) }
.firstOrNull { it.isFailure }
?: ValidatorResult.Success
}
}