Hi there. <@U02SEA99VJB> is there an ability to ta...
# akkurate
a
Hi there. @Johann Pardanaud is there an ability to take a single validation for a property? I'm working on an example with akkurate for Spring Boot + Angular to share DTOs and validations and wondering if I can have something like this:
Copy code
@Validate
data class Book(val title: String)

val bookValidator = Validator<Book> { // this: Validatable<Book>
    title.hasLengthLowerThan(50)
}

val titleValidator = bookValidator::title // Validator.Runner<String>
j
Hi Artem! If I properly understand what you're saying here, you want two independant validators? One to validate the title, and one to validate the book including the title? You can do this using composition:
Copy code
@Validate
data class Book(val title: String)

val validateTitle = Validator<String> {
    hasLengthLowerThan(50)
}

val validateBook = Validator<Book> {
    title.validateWith(titleValidator)
}

validateTitle("some title")
validateBook(Book("some title"))
Hope this helps 🙂