set.aggregate()

Aggregate all elements of a Set.

Signature

aggregate(seed: A, combiner: (A, A) => A) => A

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

Number

Yes

Initial state value.

combiner

Function

Yes

Anonymous FQL function that aggregates the elements.

Combiner function parameters:

Parameter Type Required Description

accumulator

Generic

Value returned by the previous invocation.

current

Generic

Current Set value.

Return value

Type Description

Generic

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!