1``reduce`` 2========== 3 4.. versionadded:: 2.10 5 6 The ``reduce`` filter was added in Twig 2.10. 7 8The ``reduce`` filter iteratively reduces a sequence or a mapping to a single 9value using an arrow function, so as to reduce it to a single value. The arrow 10function receives the return value of the previous iteration and the current 11value of the sequence or mapping: 12 13.. code-block:: twig 14 15 {% set numbers = [1, 2, 3] %} 16 17 {{ numbers|reduce((carry, v) => carry + v) }} 18 {# output 6 #} 19 20The ``reduce`` filter takes an ``initial`` value as a second argument: 21 22.. code-block:: twig 23 24 {{ numbers|reduce((carry, v) => carry + v, 10) }} 25 {# output 16 #} 26 27Note that the arrow function has access to the current context. 28 29Arguments 30--------- 31 32* ``arrow``: The arrow function 33* ``initial``: The initial value 34