Check out v4 of the Fauna CLI
v4 of the Fauna CLI is now in beta. The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start. |
set.aggregate()
Aggregate all elements of a Set.
Description
Aggregates all elements of the calling Set. There is no ordering expectation.
The calling Set isn’t changed.
Eager loading
This method uses eager loading and requires a read of each document in the calling Set. For large Sets, this may result in poor performance and high costs.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
seed |
Yes |
Initial state value. |
|
combiner |
Yes |
Anonymous FQL function that aggregates the elements. |
Return value
Type | Description |
---|---|
Aggregate of the iterable. If the iterable is empty, the seed is returned. |
Examples
// `toSet()` converts an Array to a Set.
let set = [1, 2, 3, 4].toSet()
set.aggregate(0, (a, b) => a + b)
10
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!