aggregate()

Aggregate all the elements in the Array.

Signature

aggregate(seed: Any, combiner: (acc: Any, val: Any) => Any): Any

Description

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

The source array isn’t changed.

Parameters

Parameter Type Required Description

seed

Any

Yes

Initial state value.

combiner

Function

Yes

Anonymous Function that aggregates the elements.

combiner parameters:

Parameter Type Required Description

acc

Any

Value returned by the previous invocation.

val

Any

Current Array 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!