Skip to content

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

list.every(element => condition)

Returns: true or false, or unknown if the list itself is unknown.

Example

[2, 4, 6].every(number => number % 2 = 0)

This returns true, since every number in the list is even.

p is Person
p.passports.every(country => country in ('ch', 'de', 'at'))

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:

p is Person
COUNT(p.passports) > 0 and p.passports.every(country => country in ('ch', 'de', 'at'))