-
How do I check that all values of a record fulfill one of several possible records? E.g. here I define two contracts and apply one of the contracts to the array of record values. How would I check if either
I tried the following but as contract failure causes an error rather than returning a boolean it obviously fails:
Hopefully it illustrates my question. And I am interested in the case where both contracts can be arbitrarily complex, rather than the simple case of checking individual numbers or strings. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
The short answer is, you can't in full generality, for good reasons. You can read this blogpost for more details about the consequences of implementing such a generic At the end of the post, we gloss over a possible limited In the meantime, it can be helpful to define independently the predicates that are used in your contracts, in order to combine them as predicates. What I mean by that is, instead of doing:
You can do
Of course, all contracts can't be defined as simple predicates (using |
Beta Was this translation helpful? Give feedback.
-
Thank you! |
Beta Was this translation helpful? Give feedback.
The short answer is, you can't in full generality, for good reasons. You can read this blogpost for more details about the consequences of implementing such a generic
or
operator.At the end of the post, we gloss over a possible limited
or
operator that would still be useful, and I imagine it could cover your use case (withNum
andStr
at least, it depends for more complex contract). To this day, this operator is not implemented, unfortunately.In the meantime, it can be helpful to define independently the predicates that are used in your contracts, in order to combine them as predicates. What I mean by that is, instead of doing: