Validatable and return the rules from
validation(), written with the validation { } block:
Account.kt
::username is the property of the object being validated. Each rule starts from a property, says
what null means for it (required, ifPresent or forbidden), and lists the constraints of
its value in the block that follows. Several constraints in one block are all checked, in order.
Checking the rules
AValidatable has four ways to run its rules. They run the same rules and differ only in how they wait and how they
answer:
Every rule runs: one object reports every broken rule at once, in the order the rules are declared. When a rule only
makes sense after another,
failFast stops at the first failure.
Conditions are plain Kotlin
The block is ordinary Kotlin code that runs when the object is validated, so the values of the object are there to read. A rule that applies only sometimes is anif or a when:
The configuration of one call
Each of the four functions takes an optionalValidity, a configuration for that call only:
other messages, or another clock.
Beside the class
For a class that is not yours, or rules that belong elsewhere.
Reading the result
ValidationResult, Violation and what each field holds.