TIL: `someFuncReturningBool() && otherFunc...
# dsl
m
TIL:
someFuncReturningBool() && otherFuncReturningBool()
and
someFuncReturningBool() and otherFuncReturningBool()
is not the same. The former short-circuits, the latter doesn’t. That hit me unexpectedly when I thought “oh that’s nice, I can just use
and
instead of
&&
in my DSL to make it more human-readable”.
Copy code
rule {
   condition {
      terms.assignmentAddress.isProvided() and
         terms.assignmentAddress.country.isNotSupported() // exception because access not allowed if isProvided() returns false
   }

   issue {
      "Terms: The address of the assignment is located in a country that is not supported."
   }
}
I presume there are only two ways to fix this. a) Use
&&
instead of
and
😥 b) Make all the functions which can be used in
condition {}
that currently return
Boolean
return something like
Condition
instead. That in turn would have an
and
infix operator which makes two
Condition
instances form a new
Condition
and thus allows for chaining with
and
. That would basically build a tree of
Condition
. I guess there are no alternatives for supporting
and
here?
e
You have to be careful,
and
is a bitwise operator not a boolean operator.
m
I know. Yet it's defined on
Boolean
, hence the confusion :)