Prism · Arrays

$reduce

Folds an array into one value. The element and what has been gathered so far are both in scope inside body; the accumulator is called acc unless named.

The source
{ numbers: [3, 1, 4, 1, 5, 9, 2, 6] }
The config
{
  $reduce: {
    over: { $ref: '$.numbers' },
    as: 'n',
    acc: 'total',
    init: { $const: 0 },
    body: { $add: [{ $var: 'total' }, { $var: 'n' }] },
  },
}
What comes out
31
Output matches the expected value

Runs in this page on the installed package. The input and the expected output are defined by the example.