-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to validate related properties #9
Comments
+1 @davidmoshal |
+1 |
Hi, Kalidation is nice because it returns Validated, a powerful arrow type. |
So just to give some silly example, in which a 3rd validation only checks, when the 2 validations it depends upon are valid cases: val specFoo = validationSpec {
constraints<Foo> {
property(Foo::foo) {
notBlank()
inValues("GREEN", "WHITE")
}
}
}
val specBar = validationSpec {
constraints<Bar> {
property(Bar::bar) {
notBlank()
inValues("CYAN", "BLACK")
}
}
}
val foo = Foo("GREEN")
val bar = Bar("BLAC")
val validFoo: Validated<Nel<String>, Foo> = specFoo.validateNel(foo)
val validBar: Validated<Nel<String>, Bar> = specBar.validateNel(bar)
validFoo.zip(validBar) { a, b ->
if (a.foo == "GREEN" && b.bar == "BLACK")
"must be green and cyan".nel().invalid()
else Pair(a, b).valid()
|
Promising library, but examples are only given for the simplest case, namely validating individual properties.
Question: can this library be used to validate related properties.
Take the following example:
How would one determine if bar and baz are both non-zero numbers, and
also that bar x baz is less than, say, 100 ?
Ideally one would be able to convert the individual properties into their typed representations, and then use them subsequently.
For example something like this (pseudo code):
ie: if bar and baz are invalid, then the subsequent calculation won't be run, otherwise it runs, with the values guaranteed to be valid.
The text was updated successfully, but these errors were encountered: