value class Validation<D, T, M>(validate: (D, T?) -> List<M>)

Encapsulates the logic for validating a given data-model and some optional metadata.

The validation logic itself is expressed by some function that must be passed as validate parameter. This function gets the actual model-data D and some optional metadata T in order to create a List of validation messages M. This value class simply wraps the provided validate function in order to make it invocable without any ceremony.

It appears to be a good practise, to put the implementation of the passed validate function right next to your data classes in the commonMain section of your Kotlin multiplatform project. So you can write the validation logic once and use them on the JS and JVM side.



data-model to validate


metadata which perhaps is needed in validation process


Link copied to clipboard
fun <D, T, M> Validation(validate: (D, T?) -> List<M>)


Link copied to clipboard
operator fun invoke(data: D, metadata: T? = null): List<M>