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
Boolean operators return inconsistent results with undefined inputs #246
Comments
If we are considering increasing the use of undefined, I think we need a function to test for this state (unless = "undefined" will work). Perhaps an $isDefined() or $exists() would be helpful here. |
|
Precisely like that ;^) thank you -- I hadn't found this when I looked. |
Thanks for raising this @deepilla. I think I favour your first suggestion
This would be consistent with the comparison operators |
Try $boolean(**.tags)
Best Regards, Nat
Nathaniel Mills
Senior Technical Staff Member - Project Lead / Chief Architect WILD Conversation Workflow Orchestration Project
Phone: 1-860-812-5089 (m)
E-mail: wnm3@us.ibm.com
----- Original message -----From: monicagarud <notifications@github.com>To: jsonata-js/jsonata <jsonata@noreply.github.com>Cc: Nathaniel Mills <wnm3@us.ibm.com>, Mention <mention@noreply.github.com>Subject: Re: [jsonata-js/jsonata] Boolean operators return inconsistent results with undefined inputs (#246)Date: Wed, Jul 18, 2018 2:24 AM
$boolean() is not working correctly for empty array as per mention in the document http://docs.jsonata.org/boolean-functions.html
check this for reference:http://try.jsonata.org/S1SR3InX7
Thank you
—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or mute the thread.
|
This issue was first raised in a Slack post. I'm reposting here (with some additional info) so it doesn't get lost.
The original poster was using the
or
operator with one falsy value and one undefined value (a non-existent path expression). They noticed that theor
operator sometimes returnedfalse
and sometimes returnedundefined
depending on the order of the operands.I tried various combinations of the
or
andand
operators with one or more undefined values (namedfoo
andbar
) and got the following results.Or
And
Note that:
Combining a falsy value with an undefined value does indeed give different results depending on the order of the operands.
There's a mix of boolean and undefined results, e.g.
true or foo
returnstrue
buttrue and foo
returnsundefined
.These are the only binary operations that produce such inconsistent results. Numeric operators (like
+
and-
) returnundefined
if either operand is undefined. Comparison operators (like=
and<
) returnfalse
if either operand is undefined. And the concatenation operator (&
) treats undefined operands as empty strings.Boolean operators should have a similarly well-defined approach to undefined inputs. I suggest one of the following:
Treat undefined operands as
false
(this would turn all of theundefined
results above tofalse
).Return
undefined
if either operand is undefined (all of the above expressions would then evaluate toundefined
).Any thoughts on this, @andrew-coleman?
The text was updated successfully, but these errors were encountered: