invoke
inline operator fun <T : Any> invoke(validations: Iterable<Validation<T>> = emptyList(), initialValue: T? = null, noinline construct: ConstructorFunction<T>? = null, builder: ClassSchemaBuilder<T>.() -> Unit): ClassSchema<T>(source)
Function used to build a schema representing values of a given class T. The children schemas are built via a class schema builder.
Example defining a PersonSchema for a class Person with name and married properties:
data class Person(var name: String, var married: Boolean)
val personSchema = ClassSchema {
Person::name { StringSchema() }
Person::married { BooleanSchema() }
}Content copied to clipboard
This schema will attempt to create values of the provided class by calling its primary constructor and matching argument names to children names. E.g. the above PersonSchema will attempt to create an instance of Person by calling Person(name, married). If the class' primary constructor has parameters with different names or requires other non-default arguments, then the user must provide a construct function, instructing how to properly construct the class.
inline operator fun <T : Any> invoke(vararg validations: Validation<T>, initialValue: T? = null, noinline construct: ConstructorFunction<T>? = null, builder: ClassSchemaBuilder<T>.() -> Unit): ClassSchema<T>(source)