Filter
Filter( arrayOrSet, lambda )
Description
The Filter
function applies the
lambda
function to each member of
arrayOrSet
, which is an Array,
Page, or Set. The
return value matches the arrayOrSet
type, and contains only those
elements for which the lambda
function returns true
.
Providing a lambda
function which does not return a
Boolean results in an "invalid argument"
error. If a Page is passed, its decorated fields are preserved in the
result.
The run time of To work around this, you may specify a larger query timeout via the driver that you are using. |
Examples
The query below iterates over the array containing the values 1, 2,
3, executing the lambda function for each value. The lambda function
returns true
if the Modulo 2 of the
value is 0, otherwise it returns false
.
client.query(
q.Filter(
[1, 2, 3],
q.Lambda(
'i',
q.Equals(0, q.Modulo(q.Var('i'), 2)),
),
)
)
.then((ret) => console.log(ret))
[ 2 ]
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!