Skip to content
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

document that all on an empty set returns false #105

Open
panzi opened this issue Aug 23, 2021 · 0 comments
Open

document that all on an empty set returns false #105

panzi opened this issue Aug 23, 2021 · 0 comments

Comments

@panzi
Copy link
Contributor

panzi commented Aug 23, 2021

In every other language all() (or every()) returns true for an empty set (see e.g. every() in JavaScript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every#description). This is because it is defined as (except with short circuiting):

let every = (array, func) => array.reduce((a, b) => a && func(b), true);

json-logic-js/logic.js

Lines 317 to 319 in c1dd82f

if ( ! scopedData.length) {
return false;
}

I know that it can't be changed now, because that would break existing code. But I suspect there is code out there that assumes that all will return true on an empty set and is already broken. What I think needs to happen is that this is mentioned in the documentation as a big fat warning, so that people are aware of this unexpected behavior and write code accordingly.

@panzi panzi changed the title all on empty array should return true document that all on an empty set returns false Aug 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant