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

commonMain.schemas.AnySchema.kt Maven / Gradle / Ivy

There is a newer version: 0.23.0
Show newest version
package io.kform.schemas

import io.kform.TypeInfo
import io.kform.Validation
import io.kform.schemas.util.commonRestrictions

/** Function responsible for creating a clone of a value of this schema. */
public typealias CloneFunction = (value: T?) -> T?

/**
 * "Catch-all" schema representing (possibly nullable) values of any given type.
 *
 * @property clone Function used to create a clone of a value of this schema.
 */
public open class AnySchema(
    validations: Iterable> = emptyList(),
    override val initialValue: T? = null,
    public val clone: CloneFunction? = null
) : AbstractSimpleSchema(validations) {
    public constructor(
        vararg validations: Validation,
        initialValue: T? = null,
        clone: CloneFunction? = null
    ) : this(validations.toList(), initialValue, clone)

    override val typeInfo: TypeInfo =
        TypeInfo(Any::class, nullable = true, restrictions = commonRestrictions(validations))

    override suspend fun clone(value: T?): T? = clone?.invoke(value) ?: value
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy