foldRight()

Collapse elements in the set, traversing right to left, give a reducer.

Signature

oldRight(seed: Any, reducer: (acc: Any, value: Any) => Any): Any

Description

The foldRight() method collapses elements in the set, traversing right to left, using the reducer function and passing the last set on the first call.

The source set isn’t changed.

Parameters

Parameter Type Required Description

seed

Any

Yes

Initial state value provided to the reducer Function.

reducer

Function

Yes

Anonymous Function to invoke for each Set value.

reducer parameters:

Parameter Type Required Description

acc

Any

Yes

Value returned by the previous invocation of reducer. On the first invocation of reducer, seed is passed as the acc (accumulator).

value

Any

Yes

Current Set value.

Return value

Type Description

Any

Result of the last reducer invocation.

Examples

let iter = [1, 2, 3]
iter.foldRight(100, (value, elem) => value + elem)
106

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!