// Example of a reduce expression. The optional object is empty and
// serves as the $output during iteration. The last step in the iteration
// sets $output. if ther are no more iterations, the $output is returned
// and provided to the next step in the pipeline.
// If data is:
// { response: ['a', 'b', 'c'] }
// The reduced/transformed expression will be:
// { 'a': 0, 'b': 1, 'c': 2 }
// Arrays and objects may be iterated over and transformed.
//YAML
'@pipe':
- ['{data.response}', {}]
- '@reduce':
- '@pipe':
- ['{$output}']
- '@pipe':
- ['{$item}']
- '@pipe':
- ['{$index}']
- ['{@object.set}']
Reduce is similar to Pipe in that it represents a new context and may include an array of
PipeItem[],PipeObject, orReduceObject. But it also iterates and produces output. The context variables,$input,$output,$item,$key, and$indexare available.