Skip to content

find()

Info

New in Atfinity 17.

Description

find() returns the first element of a list for which the condition holds, and unknown if no element matches. It stops at that element, so the rest of the list is never evaluated.

Where filter() returns every match as a list, find() returns a single element you can go on to use directly, for example by reading an attribute off it.

Syntax

list.find(element => condition)

Returns: the first matching element, or unknown if none matches.

Example

[1, 5, 9, 12].find(number => number > 6)

This returns 9, the first number greater than 6, and not 12.

p is Person
p.countries_lived_in.find(country => country != 'ch')

This returns the first country in the list that is not Switzerland.

Empty lists

[].find(number => number > 0) evaluates to unknown, and so does a list where nothing matches, and so does a list that is itself unknown. find() therefore cannot tell those three apart, and neither can a rule reading its result. count() and some() collapse the empty list and the failed search in the same way, so where the difference matters, test the list itself with COUNT(list) > 0.