commonMain.neat.ValidatorUtils.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
The newest version!
package neat
import neat.internal.OptionalValidator
import neat.internal.RequiredValidator
import neat.internal.ValidatingFunction
fun Validator.root(key: String): ValidatingFunction<*, *>? {
val optionals = (this as? OptionalValidator<*>)?.validators?.functions ?: emptyMap()
val required = (this as? RequiredValidator<*>)?.validators?.functions ?: emptyMap()
return buildMap {
putAll(optionals)
putAll(required)
}[key]
}
inline fun Validator<*>.int(key: String) = root(key)?.metadata as? Int
inline fun Validator.set(builder: Validator.() -> Validator): Validator = builder()
inline val Validator<*>.required get() = this is RequiredValidator<*>
inline val Validator<*>.optional get() = this is OptionalValidator<*>