Check the final option value and raise an error if it's not valid.

The validator is called with the final option type (the output of transformAll), and should call fail if the value is not valid. The validator is not called if the delegate value is null.

Your validator can also call require to fail automatically if an expression is false, or message to show the user a warning message without aborting.


val opt by option().int().validate { require(it % 2 == 0) { "value must be even" } }