FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date. For more details, review the migration guide. Contact support@fauna.com with any questions. |
Foreach
This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics. |
Foreach( array_or_page, lambda )
foreach( lambda, array_or_page )
Foreach( array_or_page, lambda )
Foreach( array_or_page, lambda )
Foreach( array_or_page, lambda )
Description
The Foreach
function applies the Lambda
serially to each
member of an Array or Page, and returns the original,
unmodified array.
The Foreach
function is very useful when the original array does
not need to be modified, but a side effect is required for every value
in an array. Later invocations of the Lambda can see the side effects of
earlier invocations of the Lambda.
Parameters
Parameter | Type | Definition and Requirements |
---|---|---|
|
Array or Page |
The Array or Page over which the |
|
The anonymous function to be executed. |
Examples
The following query iterates over the results returned by the
Paginate
function, executing the Lambda for each value in the
page of results. The page of results contains an array of references,
and each reference’s document is updated by the Lambda.
{
data: [
Ref(Collection("spells"), "181388642046968320"),
Ref(Collection("spells"), "181388642071085568")
]
}
{'data': [Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections))), Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections)))]}
map[data:[{181388642046968320 0xc00008e300 0xc00008e300 <nil>} {181388642071085568 0xc00008e4b0 0xc00008e4b0 <nil>}]]
ObjectV(data: Arr(RefV(id = "181388642046968320", collection = RefV(id = "spells", collection = RefV(id = "collections"))), RefV(id = "181388642071085568", collection = RefV(id = "spells", collection = RefV(id = "collections")))))
{
data: [
Ref(Collection("spells"), "181388642046968320"),
Ref(Collection("spells"), "181388642071085568")
]
}
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!