2 ms·
It helps to think in terms of `any` first: any([], predicate) => false This is plainly obvious, because it is illogical to say "the predicate is true for at
by cheald 3y ago
It helps to think in terms of `any` first:
any([], predicate) => false
This is plainly obvious, because it is illogical to say "the predicate is true for at least one member of the empty set".
If we can agree on that, then all([], predicate) must be true, because the complement of all(list, predicate) is any(list, predicate')
The naive assumption is that the complement of all(list, p) is all(list, p'), but this is demonstrably false, because in the case of an empty list: all([], e => e) and all([], e => !e) would both return the same value.
> [[], [true], [false]].map(s => s.every(e => e) == !s.every(e => !e))
[ false, true, true ]
Instead, its proper complement is any(list, p'), which means that all(list, p) = !any(list, p')
> [[], [true], [false]].map(s => s.every(e => e) == !s.some(e => !e))
[ true, true, true ]
So, for all([], p) to be false, any([], p') would have to be true, which makes even less sense than all([], p) => true.