The arrow function receives the return value of the previous iteration and the current value of the sequence or mapping:

{% set numbers = [1, 2, 3] %}

{{ numbers | reduce((carry, v) => carry + v) }}
{# output 6 #}

The reduce filter takes an initial value as a second argument:

{{ numbers | reduce((carry, v) => carry + v, 10) }}
{# output 16 #}

Note that the arrow function has access to the current context.

Arguments

ArgumentDescriptionType
arrowThe arrow functionFunction
initialThe initial valueString

Was this helpful?

Copyright © 2024 Blutui.