dave08
01/06/2025, 2:47 PMotherwise { }
only supports strings right? It's not so great when validating forms in Jetpack Compose where an error is an R.string.XXX (an Int...)... any chance of expanding that to support other types?Johann Pardanaud
01/06/2025, 2:49 PMJohann Pardanaud
01/06/2025, 2:49 PMJohann Pardanaud
01/06/2025, 2:49 PMdave08
01/06/2025, 2:55 PMval validateBook = Validator<Book> {
title.isNotEmpty() otherwise { R.string.missingTitle }
releaseDate.isInPast() otherwise { R.string.releaseDateMustBeInPast to listOf(releaseDate.value) } // In some cases a stringResource is a template with interpolation of values so here it would be nice to pass in a Pair...
authors.hasSizeBetween(1..10) otherwise { R.string.wrongAuthorCount }
authors.each {
(firstName and lastName) {
isNotEmpty() otherwise { R.string.missingName }
}
}
}
dave08
01/06/2025, 2:55 PMJohann Pardanaud
01/06/2025, 2:56 PMJohann Pardanaud
01/06/2025, 2:56 PMdave08
01/06/2025, 2:59 PMJohann Pardanaud
01/06/2025, 3:26 PMJavier
01/06/2025, 3:44 PMResult
has and Either
fixed. The left part not being a generic and force to use Exception
.
Validator<Int, Book> { }
Validator<() -> String, Book> { }
If it uses a generic you wouldn't need any integration with any library, but you can still provide bindings for them anyway.
Not good names but to show some samples:
ValidatorOrResource<Book> { }
ValidatorOrComposeResource<Book> { }
Johann Pardanaud
01/06/2025, 3:53 PMdave08
01/06/2025, 3:55 PMThe book %s is invalid
needs the book name there...dave08
01/06/2025, 3:56 PMPair<Int, List<Any>>
returned in one validation up there...dave08
01/06/2025, 3:56 PMJohann Pardanaud
01/06/2025, 3:57 PM