every()¶
Info
New in Atfinity 17.
Description¶
every() checks a condition against each element of a list and returns true only if the condition holds for all of
them.
It stops at the first element that fails, so a long list costs nothing once the answer is settled.
Use it instead of ALL whenever the condition has to be written out.
ALL tests the values it is handed, so expressing a condition with it takes a map() first:
list.every(x => x > 0) and ALL(list.map(x => x > 0)) answer the same question, and the first states the condition
once.
Syntax¶
Returns: true or false, or unknown if the list itself is unknown.
Example¶
This returns true, since every number in the list is even.
This returns true if the person holds no passport outside Switzerland, Germany and Austria.
Empty lists¶
[].every(number => number > 0) evaluates to true.
See the ALL page for the rationale, which is the same one.
To require at least one element as well, check the length: