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

commonMain.neat.ValidatorUtils.kt Maven / Gradle / Ivy

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<*>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy