How to chain validators?

I have written an own dialog, which validates the input. Subdialogs can override this validator. Since I want to reuse the super validator, I would like to chain them, but when I do Validator.andThen, it returns a BiFunction, which not aligns with the Validator type anymore. How can this be achieved?

I have to correct, andThen is obviously wrong, because it continues with the ValidationResult. But my main questions still stands, are there any utility functions to chain validators or do I have to write my own logic? If I have to write it by myself, I think it would nice to have it in vaadin itself.

Normally Binder are used for those kind of actions. It’s also possible to have List allowing you do execute all validations defined for your components that have registered their bindings.

Using a binder could be possible, but requires to much refactoring for now. I also think its a bit to heavy for the use case.
What do you mean with List ?

For now I have created a utility function (kotlin):

    fun <T> chain(vararg validators: Validator<T>): Validator<T> = Validator { value, ctx ->
        validators.asSequence().map { it.apply(value, ctx) }.firstOrNull { it.isError } ?: ValidationResult.ok()

List of Binders :wink: Binder1 + Binder2 added to one list and later iterate over the list to trigger all validations

But that would require to instantiate multiple binders, if I only need the validation logic, without binding to a field etc.