count()¶
Info
New in Atfinity 17.
Description¶
count() returns how many elements of a list satisfy a condition.
It is not the method version of COUNT, which takes no condition and returns a length.
The two agree where the condition holds for every element, as in list.count(x => true).
Reach for count() when you want a subset counted, and COUNT when you want a length.
count() only accepts a list, while COUNT also measures a dictionary or a string.
list.count(x => condition) is also shorter than COUNT(list.filter(x => condition)), and it does not build the
intermediate list.
Syntax¶
Returns: a number, or unknown if the list itself is unknown.
Example¶
This returns 3, for the elements 3, 4 and 5.
This is true if the person has lived in more than two countries outside Switzerland.
Empty lists¶
[].count(number => number > 0) evaluates to 0.