aggregate()

Aggregate all the elements in the set.

Signature

aggregate(seed: T, combiner: (a: T, b: T) => T): T

Description

The aggregate() method aggregates all array elements. There is no ordering expectation.

The source set isn’t changed.

Parameters

Parameter Type Required Description

seed

Number

Yes

Initial state value.

combiner

Function

Yes

Anonymous Function that aggregates the elements.

combiner parameters:

Parameter Type Required Description

a

Any

Value returned by the previous invocation.

b

Any

Current Set value.

Return value

Type Description

Any

Aggregate of the iterable. If the iterable is empty, seed is returned.

Examples

let iter = [1, 2, 3, 4]
iter.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!