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

What's the difference between A.all and A.every, A.any and A.some? #118

Open
ThatsEmbarrassing opened this issue Oct 5, 2024 · 2 comments

Comments

@ThatsEmbarrassing
Copy link

According to the documentation, there are four functions to check if the whole array or at least one element of it satisfies the condition.

However, I don't see the difference between them, because they act the same.

// A.all / A.every

console.log(A.all([2, 4, 6, 8, 10], (value) => value % 2 === 0)); // true
console.log(A.every([2, 4, 6, 8, 10], (value) => value % 2 === 0)); // true

console.log(A.all([1, 4, 5, 7, 9], (value) => value % 2 === 0)); // false
console.log(A.every([1, 4, 5, 7, 9], (value) => value % 2 === 0)); // false

console.log(A.all([1, 3, 5, 7, 9], (value) => value % 2 === 0)); // false
console.log(A.every([1, 3, 5, 7, 9], (value) => value % 2 === 0)); // false
// A.any / A.some

console.log(A.any([2, 4, 6, 8, 10], (value) => value % 2 === 0)); // true
console.log(A.some([2, 4, 6, 8, 10], (value) => value % 2 === 0)); // true

console.log(A.any([1, 4, 5, 7, 9], (value) => value % 2 === 0)); // true
console.log(A.some([1, 4, 5, 7, 9], (value) => value % 2 === 0)); // true

console.log(A.any([1, 3, 5, 7, 9], (value) => value % 2 === 0)); // false
console.log(A.some([1, 3, 5, 7, 9], (value) => value % 2 === 0)); // false

It's not said if the one function of them is an alias for another and their declarations are a bit only different. So I find it confusing for developers using this library.

@JUSTIVE
Copy link

JUSTIVE commented Nov 27, 2024

let all = (xs, predicateFn) => Belt.Array.everyU(xs, (. value) => predicateFn(value))
let every = (xs, fn) => Belt.Array.everyU(xs, fn)

let any = (xs, predicateFn) => Belt.Array.someU(xs, (. value) => predicateFn(value))
let some = (xs, fn) => Belt.Array.someU(xs, fn)

they are exactly the same. both calls Belt's Array.everyU, Array.someU

@JUSTIVE
Copy link

JUSTIVE commented Nov 27, 2024

There are many names for the same idea, such as for all, every, universal quantification, and every.
but I also agree that many names for the same idea, in a single library is not a good idea.

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

2 participants