Actionable: Logical operators should return the truthy/falsy value that triggered their return #3415
gwhitney
started this conversation in
Design decisions
Replies: 1 comment 4 replies
-
|
I quite like that the boolean operators just return a boolean, it's clear and straightforward. For your case |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently they always convert their outputs to boolean, losing the information of what exactly truthy/falsy value was input. But in many languages,
andof a number of arguments returns the first "falsy" argumen, or the last argument if they are all "truthy", whereasorof a number of arguments returns the first "truthy" argument, or the last argument if they are all "falsy". Here "falsy" means "converts to boolean false" and analogously for "truthy". For example,2 or falsewould return2under this alternate convention. This alternative version of the logical operators can be very useful for producing concise formulas that filter out bad values, avoiding ternaries likex ? x : falseand the like. If there was interest in adopting a revised convention, it would be a breaking change, but it would be convenient to implement it along with fixes to #3414.Beta Was this translation helpful? Give feedback.
All reactions