How to validate a Map
?
#38
Answered
by
nesk
rektplorer64
asked this question in
Q&A
-
Is it possible to:
|
Beta Was this translation helpful? Give feedback.
Answered by
nesk
Jul 29, 2024
Replies: 1 comment
-
Yes, this is supported: val mapValidator = Validator<Map<String, Int>> {
// Validate a specific key
this["key7"] { // this: Validatable<Int?>
isNotNull()
}
// Iterate over keys
keys.each { // this: Validatable<String>
isGreaterThanOrEqualTo(30)
}
// Iterate over values
values.each { // // this: Validatable<Int>
isGreaterThanOrEqualTo(30)
}
// Iterate over entries
entries.each {// this: Validatable<Map.Entry<String, Int>>
constrainIfNotNull { (key, value) -> '2' !in key }
.otherwise { "Must not have 2 in key" }
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
nesk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, this is supported: